-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
100 lines (80 loc) · 2.7 KB
/
Copy path__main__.py
File metadata and controls
100 lines (80 loc) · 2.7 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""2026-05-29
Planning Session 02
Lembranças de um planejamento com post its
ericof.com|https://ericof.com/en/sketches/2024-10-19
png
Sketch,py5,CreativeCoding
"""
from random import shuffle
from sketches.utils.draw import canvas
from sketches.utils.draw.cores.paletas import gera_paleta
from sketches.utils.draw.grade import cria_grade
from sketches.utils.helpers import sketches as helpers
import py5
sketch = helpers.info_for_sketch(__file__, __doc__)
cor_fundo = py5.color(0)
celula_x = 80
celula_y = 80
largura_base = 70
altura_base = 70
traco_peso_min = 4
traco_peso_max = 6
GRADE: list[tuple[tuple[float, float], py5.Py5Shape]] = []
def calcula_grade() -> list[tuple[tuple[float, float], py5.Py5Shape]]:
"""Monta as formas da grade posicionadas sobre a area interna do canvas.
Para cada ponto da grade (embaralhada) cria um retangulo com cor de
preenchimento sorteada da paleta ``Navy-Orange``, traco preto de peso
aleatorio, escala aleatoria e rotacao que cresce conforme a posicao
``x``/``y`` do ponto.
:returns: pares ``((x, y), forma)`` com a posicao e a forma a desenhar.
"""
grade = []
paleta = gera_paleta("Navy-Orange", False)
pontos = cria_grade(*helpers.DIMENSOES.internal, 0, 0, celula_x, celula_y, False)
shuffle(pontos)
for x, y in pontos:
cor_interna = py5.color(py5.random_choice(paleta))
traco = py5.color("#000")
peso = py5.random_int(traco_peso_min, traco_peso_max)
mult = py5.random(1.2, 1.5)
largura = largura_base * mult
altura = altura_base * mult
rotacao_max = float(
py5.remap(y, -200, 1000, 0, 15) + py5.remap(x, -200, 1000, 0, 2)
)
rotacao = float(py5.radians(py5.random(-rotacao_max, rotacao_max)))
forma = py5.create_shape(py5.RECT, 0, 0, largura, altura)
forma.set_stroke(traco)
forma.set_stroke_weight(peso)
forma.set_fill(cor_interna)
forma.rotate(rotacao)
grade.append(((x, y), forma))
return grade
def setup():
py5.size(*helpers.DIMENSOES.external, py5.P3D)
py5.rect_mode(py5.CORNER)
GRADE.extend(calcula_grade())
def draw():
py5.background(cor_fundo)
with py5.push():
py5.translate(*helpers.DIMENSOES.pos_interno, 0)
for (x, y), forma in GRADE:
py5.shape(forma, x, y)
# Credits and go
canvas.sketch_frame(
sketch,
cor_fundo,
"large_transparent_white",
"transparent_white",
version=2,
)
def key_pressed():
key = py5.key
if key == " ":
save_and_close()
def save_and_close():
py5.no_loop()
canvas.save_sketch_image(sketch)
py5.exit_sketch()
if __name__ == "__main__":
py5.run_sketch()