1+ import time
2+ import pygame
3+ import pmma
4+ import random
5+
6+ pmma .init ()
7+
8+ display = pygame .display .set_mode ((0 , 0 ), pygame .FULLSCREEN )
9+ clock = pygame .time .Clock ()
10+
11+ class Pane :
12+ def __init__ (self ):
13+ self .noise = pmma .Perlin ()
14+ self .points = []
15+ self .surface = pygame .Surface ((display .get_width (), display .get_height ()))
16+ self .r_diff = random .randint (- 20 , 20 )
17+ self .g_diff = random .randint (- 20 , 20 )
18+ self .b_diff = random .randint (- 20 , 20 )
19+
20+
21+ def render (self , col ):
22+ col = [col [0 ]+ self .r_diff , col [1 ]+ self .g_diff , col [2 ]+ self .b_diff ]
23+ if col [0 ] > 255 :
24+ col [0 ] = 255
25+ elif col [0 ] < 0 :
26+ col [0 ] = 0
27+
28+ if col [1 ] > 255 :
29+ col [1 ] = 255
30+ elif col [1 ] < 0 :
31+ col [1 ] = 0
32+
33+ if col [2 ] > 255 :
34+ col [2 ] = 255
35+ elif col [2 ] < 0 :
36+ col [2 ] = 0
37+
38+ self .surface .fill ([0 , 0 , 0 ])
39+ if len (self .points ) > display .get_width ():
40+ del self .points [0 ]
41+ self .points .append (self .noise .generate_1D_perlin_noise (now_time / 30 , new_range = [0 , display .get_height ()]))
42+
43+ points = [(0 , display .get_height ())]
44+ for i , point in enumerate (self .points ):
45+ points .append ((i , point ))
46+ points .append ((display .get_width (), display .get_height ()))
47+
48+ if len (points ) > 5 :
49+ pygame .draw .polygon (self .surface , col , points , 0 )
50+ self .surface .set_colorkey ([0 , 0 , 0 ])
51+ self .surface .set_alpha (100 )
52+ display .blit (self .surface , (0 , 0 ))
53+
54+ N = 5
55+ panes = []
56+ for _ in range (N ):
57+ pane = Pane ()
58+ panes .append (pane )
59+
60+ color = pmma .ColorConverter ()
61+ start = time .perf_counter ()
62+ now_time = 0
63+ while True :
64+ #display.fill(pygame.transform.average_color(display))
65+ display .fill ([255 , 255 , 255 ])
66+ for event in pygame .event .get ():
67+ if event .type == pygame .QUIT :
68+ pygame .quit ()
69+ pmma .quit ()
70+ quit ()
71+ elif event .type == pygame .KEYDOWN :
72+ if event .key == pygame .K_ESCAPE :
73+ pygame .quit ()
74+ pmma .quit ()
75+ quit ()
76+
77+ generated_color = color .generate_color (now_time / 25 , format = pmma .Constants .RGB )
78+
79+ for pane in panes :
80+ pane .render (generated_color )
81+
82+ pygame .display .flip ()
83+ clock .tick (60 )
84+ now_time = time .perf_counter () - start
0 commit comments