/
2dnoise.py
69 lines (50 loc) · 1.75 KB
/
2dnoise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import game
import noise
import random
import pygame
from pygame.locals import *
class NoiseCreator(object):
"""???"""
def __init__(self, screen_width, screen_height):
super(NoiseCreator, self).__init__()
self.screen_width = screen_width
self.screen_height = screen_height
self.image = pygame.Surface([640, 480])
def display(self, surface):
surface.blit(self.image, (0, 0))
def generate(self, octaves, persistance, lacunarity):
base_x = random.randint(0, 100)
base_y = random.randint(0, 100)
for x in range(self.screen_width):
for y in range(self.screen_height):
xoff = (x / self.screen_width * 7) + base_x
yoff = (y / self.screen_height * 7) + base_y
color = int(abs(noise.pnoise2(
xoff, yoff,
octaves,
persistance,
lacunarity) * 3333))
self.image.set_at(
(x, y),
(color % 255, color % 255, color % 255))
class SimpleWindow(game.Game):
"""Simple Window to display stuff"""
def __init__(self):
super(SimpleWindow, self).__init__()
self.overwrite = True
self.FPS = 1
self.nc = NoiseCreator(self.WINDOWWIDTH, self.WINDOWHEIGHT)
self.nc.generate(1, 0.5, 2)
def update(self, delta):
octaves = 2
persistance = .4
lacunarity = 3
print(octaves, persistance, lacunarity)
self.nc.generate(octaves, persistance, lacunarity)
def evnt_hndlr(self, event):
pass
def draw(self, surf):
self.nc.display(surf)
if __name__ == '__main__':
simpleWindow = SimpleWindow()
simpleWindow.run()