-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
91 lines (75 loc) · 2.17 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
"""2024-08-31
Fraturas Circulares
Inspirado por @[email protected], implementa um círculo fraturado em pequenos segmentos
png
Sketch,py5,CreativeCoding
"""
from collections import deque
from copy import deepcopy
import numpy as np
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
MARGEM_X = 0
MARGEM_Y = 0
LARGURA = 80
ALTURA = 80
PALETA = deque(
[
"#7ec0e0",
"#1c8eaf",
"#032035",
"#fdaa08",
"#f87109",
]
)
def gera_grade(
x0: int, y0: int, x1: int, y1: int, n_colunas: int, n_linhas: int
) -> list:
tam_paleta = len(PALETA)
altura = int((y1 - y0) / n_linhas)
largura = int((x1 - x0) / n_colunas)
y_ = np.linspace(y0, y1, num=n_linhas, endpoint=False)
x_ = np.linspace(x0, x1, num=n_colunas, endpoint=False)
grade = []
for idy, y in enumerate(y_):
for idx, x in enumerate(x_):
paleta = deepcopy(PALETA)
id_cor = (idx + idy) % tam_paleta
paleta.rotate(-id_cor)
fundo = paleta.pop()
pg = py5.create_graphics(largura, altura)
pg.begin_draw()
pg.background(fundo)
for iidx, diametro in enumerate(range(760, 5, -30)):
pg.stroke(paleta[iidx % (tam_paleta - 1)])
pg.stroke_weight(30)
y_c = -y + py5.random_int(-2, 2)
pg.circle(-x, y_c, diametro)
pg.end_draw()
grade.append(((x, y), pg))
return grade
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.background(0)
py5.color_mode(py5.RGB)
meio_x = py5.width / 2
meio_y = py5.height / 2
py5.no_fill()
py5.blend_mode(py5.BLEND)
with py5.push_matrix():
py5.translate(meio_x, meio_y)
grade = gera_grade(-meio_x, -meio_y, meio_x, meio_y, 10, 10)
for (x, y), pg in grade:
py5.image(pg, x, y)
helpers.write_legend(sketch=sketch)
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()