-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlines.py
65 lines (53 loc) · 1.45 KB
/
lines.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
import pygame
import pmma
import time
pygame.init()
pmma.init()
display = pygame.display.set_mode((1920, 1080), pygame.FULLSCREEN)
clock = pygame.time.Clock()
class Line:
def __init__(self, y_pos):
self._noise = pmma.Perlin(seed=0)
self._y_pos = y_pos
self._points = []
def render(self, col):
C = 750
filled = False
points = []
self._points.append(self._y_pos + self._noise.generate_2D_perlin_noise(now_time/5, self._y_pos/200, new_range=[-80, 80]))
lx = 0
for x in range(len(self._points)):
points.append([lx, self._points[x]])
lx = (1920 / len(self._points))*x
if len(self._points) > C:
del self._points[0]
filled = True
try:
pygame.draw.lines(display, col, False, points, 3)
except:
pass
return filled
N = 50
y_pos = 0
lines = []
for i in range(N):
lines.append(Line(y_pos))
y_pos += 1080 / N
color = pmma.ColorConverter()
start = time.perf_counter()
now_time = 0
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
col = color.generate_color_from_perlin_noise(now_time/5)
display.fill((0, 0, 0))
for line in lines:
f = line.render(col)
pygame.display.update()
if f:
clock.tick(60)
else:
clock.tick(2000)
now_time = time.perf_counter() - start