-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolored glass panes.py
84 lines (69 loc) · 2.29 KB
/
colored glass panes.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import time
import pygame
import pmma
import random
pmma.init()
display = pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
clock = pygame.time.Clock()
class Pane:
def __init__(self):
self.noise = pmma.Perlin()
self.points = []
self.surface = pygame.Surface((display.get_width(), display.get_height()))
self.r_diff = random.randint(-20, 20)
self.g_diff = random.randint(-20, 20)
self.b_diff = random.randint(-20, 20)
def render(self, col):
col = [col[0]+self.r_diff, col[1]+self.g_diff, col[2]+self.b_diff]
if col[0] > 255:
col[0] = 255
elif col[0] < 0:
col[0] = 0
if col[1] > 255:
col[1] = 255
elif col[1] < 0:
col[1] = 0
if col[2] > 255:
col[2] = 255
elif col[2] < 0:
col[2] = 0
self.surface.fill([0, 0, 0])
if len(self.points) > display.get_width():
del self.points[0]
self.points.append(self.noise.generate_1D_perlin_noise(now_time/30, new_range=[0, display.get_height()]))
points = [(0, display.get_height())]
for i, point in enumerate(self.points):
points.append((i, point))
points.append((display.get_width(), display.get_height()))
if len(points) > 5:
pygame.draw.polygon(self.surface, col, points, 0)
self.surface.set_colorkey([0, 0, 0])
self.surface.set_alpha(100)
display.blit(self.surface, (0, 0))
N = 5
panes = []
for _ in range(N):
pane = Pane()
panes.append(pane)
color = pmma.ColorConverter()
start = time.perf_counter()
now_time = 0
while True:
#display.fill(pygame.transform.average_color(display))
display.fill([255, 255, 255])
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
pmma.quit()
quit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
pygame.quit()
pmma.quit()
quit()
generated_color = color.generate_color_from_perlin_noise(now_time/25, format=pmma.Constants.RGB)
for pane in panes:
pane.render(generated_color)
pygame.display.flip()
clock.tick(60)
now_time = time.perf_counter() - start