-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl4.py
84 lines (58 loc) · 1.83 KB
/
l4.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 pgzrun
import random
################################# CONSTANTS #################################
WIDTH = 500
HEIGHT = 500
BCKG_COLOR = 127, 127, 127
LINES = 8
COLUMNS = 7
BRICK_WIDTH = 50
BRICK_HEIGHT = 20
BRICK_SIZE = BRICK_WIDTH, BRICK_HEIGHT
BRICK_H_DISTANCE = 5
BRICK_V_DISTANCE = 3
H_OFFSET = 40
V_OFFSET = 30
############################# Brick Generation #############################
def generate_bricks():
bricks = []
for i in range(LINES):
line = []
for j in range(COLUMNS):
horizontal_pos = (BRICK_WIDTH + BRICK_H_DISTANCE) * j + H_OFFSET
vertical_pos = (BRICK_HEIGHT + BRICK_V_DISTANCE) * i + V_OFFSET
brick_pos = horizontal_pos, vertical_pos
brick = Rect(brick_pos, BRICK_SIZE)
line.append(brick)
bricks.append(line)
return bricks
bricks = generate_bricks()
################################# Colors #################################
def random_color():
r = random.randrange(50, 256)
g = random.randrange(50, 256)
b = random.randrange(50, 256)
return r, g, b
def generate_colors():
colors = []
for i in range(LINES):
line = []
for j in range(COLUMNS):
line.append(random_color())
colors.append(line)
return colors
colors = generate_colors()
################################# Pad #################################
pad_size = 120, 15
PAD_V_OFFSET = 50
pad = Rect((WIDTH // 2 - pad_size[0] // 2, HEIGHT - PAD_V_OFFSET), pad_size)
pad_color = 0, 0, 0
################################ PGZ Framework ################################
def draw():
screen.clear()
screen.fill(BCKG_COLOR)
for i in range(LINES):
for j in range(COLUMNS):
screen.draw.filled_rect(bricks[i][j], colors[i][j])
screen.draw.filled_rect(pad, pad_color)
pgzrun.go()