-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
93 lines (77 loc) · 2.26 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
91
92
93
"""2024-08-03
Padrões 8
Exercício de criação de padrões circulares dentro de uma grade
png
Sketch,py5,CreativeCoding,abav
"""
from random import choice
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
GRADE = []
QUADRADO = 96
POS = [
(QUADRADO, 0),
(0, QUADRADO),
(QUADRADO, QUADRADO),
(0, 0),
]
POS_R = [
(0, QUADRADO),
(QUADRADO, 0),
(0, 0),
(QUADRADO, QUADRADO),
]
def setup():
global PG
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
for idy, y in enumerate(range(100, 700, 100), 1):
for idx, x in enumerate(range(100, 700, 100), 1):
canal = (idy + idx) % 2
pg = py5.create_graphics(QUADRADO, QUADRADO)
fundo = (240, 233, 211)
if canal == 1:
fundo = (0, 0, 0)
num_circulos = py5.random_int(10, 20)
circulos = []
pos = choice(POS)
pos_r = POS_R[POS.index(pos)]
passo = 200 // num_circulos
for idc in range(num_circulos):
valor = (passo * idc) + 55
cor = [0, 0, 0]
cor[canal] = valor
tamanho = py5.random_int(2, QUADRADO)
passo = py5.TWO_PI / py5.random_int(2, 22)
circulos.append((pos, tamanho, cor))
circulos.append((pos_r, tamanho, cor))
GRADE.append((pg, (x, y), (idx, idy), fundo, passo, circulos))
def draw():
py5.background(10, 10, 10)
f = py5.frame_count
i = 0
for pg, (x, y), (idx, idy), fundo, passo, circulos in GRADE:
pg.begin_draw()
pg.background(*fundo)
for circulo in circulos:
(xc, yc), d, cor = circulo
s = py5.cos(py5.radians(f * 2) + i * passo)
d += 65 * s
pg.no_fill()
pg.stroke(*cor)
pg.stroke_weight(QUADRADO / abs(d))
pg.circle(xc, yc, d)
pg.end_draw()
py5.image(pg, x, y)
i += 1
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()