-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSquare.py
More file actions
77 lines (57 loc) · 1.79 KB
/
Square.py
File metadata and controls
77 lines (57 loc) · 1.79 KB
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
import pygame
Win = pygame.display.set_mode((1920,1200), pygame.NOFRAME)
clock = pygame.time.Clock()
class Square:
def __init__(self, pos) -> None:
self.x, self.y = pos
self.width = 10
self.height = 10
self.r_weight = 1
self.b_weight = 1
self.r_max = False
self.r = 0
self.b = (self.y/10) * self.b_weight
self.rect = pygame.Rect(self.x, self.y, self.width, self.height)
self.color = (self.r, 0, self.b)
def draw(self):
pygame.draw.rect(Win, self.color, self.rect)
def gradient_shift(self):
if self.r_max == False:
self.r += 1
if self.r >= 240:
self.r_max = True
else:
self.r -= 2
if self.r <= 0:
self.r_max = False
self.color = (self.r, 0, self.b)
self.draw()
def check_exit_button(event, bool):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
bool = False
return bool
def create_squares():
squares = []
for i in range(0,1920,10):
for j in range(0,1200,10):
squares.append(Square((i,j)))
return squares
def draw_squares(queue):
for ele in queue:
ele.draw()
ele.gradient_shift()
def change_square_color(queue):
for ele in queue:
ele.gradient_shift()
def main():
run = True
queue = create_squares()
draw_squares(queue)
while run:
for event in pygame.event.get():
run = check_exit_button(event, run)
change_square_color(queue)
pygame.display.update()
clock.tick(30)
main()