-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
90 lines (73 loc) · 2.2 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-08-21
Concêntrico 5
Exercício de criação de sketch baseado em formas geométricas concêntricas
png
Sketch,py5,CreativeCoding,Geometry
"""
import numpy as np
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
FUNDO = (46, 12, 98)
def calcula_circulo(diametro: int) -> list[tuple[int, int]]:
pontos = []
raio = diametro // 2
n = 360
for ponto in range(0, n + 1):
x = np.cos(2 * py5.PI / n * ponto) * raio
y = np.sin(2 * py5.PI / n * ponto) * raio
pontos.append((int(x), int(y)))
return pontos
def poligono(pontos: list[tuple[int, int]], lados=3) -> py5.Py5Shape:
angulo = 360 / lados
s = py5.create_shape()
with s.begin_closed_shape():
for i in range(0, lados + 1):
if (idx := int(i * angulo)) > 360:
idx = idx % 360
x, y = pontos[idx]
s.vertex(x, y)
return s
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.color_mode(py5.HSB, 360, 100, 100)
py5.background(*FUNDO)
pontos = calcula_circulo(800)
py5.shape_mode(py5.CORNERS)
py5.blend_mode(py5.BLEND)
h = 126
s = 12
b = 97
with py5.push_matrix():
py5.translate(py5.width // 2, py5.height // 2)
lados = 6
tamanhos = list(range(1120, 20, -10))
total = len(tamanhos)
rot = 0
forma = poligono(pontos, lados)
for idx, tamanho in enumerate(tamanhos):
mult = 1 - (idx / total)
resto = idx % 3
if not resto:
cor_pintura = py5.color(*FUNDO)
else:
cor_pintura = py5.color(h, s, b * mult)
forma.no_stroke()
forma.set_fill(cor_pintura)
py5.shape(forma, 0, 0, tamanho, tamanho)
forma.rotate(py5.radians(rot))
if idx % 4:
rot -= 6
else:
rot -= 12
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()