-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
90 lines (72 loc) · 2.32 KB
/
__main__.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
85
86
87
88
89
90
"""2024-06-06
Grades sobrepostas 8
Exercício de criação de grades sobrepostas
png
Sketch,py5,CreativeCoding
"""
from dataclasses import dataclass
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
@dataclass
class Celula:
x: int
y: int
pg: py5.Py5Graphics
largura: int
altura: int
fundo: tuple[int, int, int]
GRADES: list[list[Celula]] = []
PASSO: int = 100
QUADRADO: int = 120
DIFF_PASSO_QUADRADO: int = PASSO - QUADRADO
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.color_mode(py5.HSB, 360, 100, 100)
py5.background(0)
params = [
(-600 + (i * PASSO / 2), 600 - (i * PASSO / 2), PASSO) for i in range(0, 12)
]
for idx, (pi, pf, passo) in enumerate(params):
GRADES.append([])
pi = int(pi)
pf = int(pf)
for x in range(pi, pf, passo):
for y in range(pi, pf, passo):
pg = py5.create_graphics(QUADRADO, QUADRADO)
h = (10 + (idx * 24)) % 360
s = 100
b = py5.random_int(80 - int(40 / (idx + 1)), 100 - int(40 / (idx + 1)))
cor = [h, s, b]
celula = Celula(x, y, pg, QUADRADO, QUADRADO, cor)
GRADES[idx].append(celula)
def draw():
py5.background(0)
for idx, grade in enumerate(GRADES):
angulo = py5.radians(((idx % 4) + (idx + 1)) * 15 * py5.cos(idx * 30))
with py5.push_matrix():
py5.translate(py5.width / 2, py5.height / 2)
py5.rotate(angulo)
for _, celula in enumerate(grade):
pg = celula.pg
pg.begin_draw()
pg.shape_mode(py5.CENTER)
pg.background(*celula.fundo)
pg.end_draw()
x = celula.x + (DIFF_PASSO_QUADRADO / 2)
y = celula.y + (DIFF_PASSO_QUADRADO / 2)
with py5.push_style():
py5.stroke("#FFF")
py5.square(x - 2, y - 2, QUADRADO)
py5.image(pg, x, y)
helpers.write_legend(sketch=sketch, frame="#000")
def key_pressed():
key = py5.key
if key == " ":
save_and_close()
def save_and_close():
py5.no_loop()
helpers.save_sketch_image(sketch)
py5.exit_sketch()
if __name__ == "__main__":
py5.run_sketch()