-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
85 lines (70 loc) · 2.15 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
"""2024-04-07
Mosaico V
Exercício de criação de um mosaico em grade, utilizando elipses.
png
Sketch,py5,CreativeCoding,grid
"""
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
def cria_grade(
margem_x: int, margem_y: int, celula_x: int, celula_y: int, alternada: bool = True
):
"""Cria uma grade."""
pontos = []
celula_x = int(celula_x)
celula_y = int(celula_y)
yi = margem_y
yf = py5.height - margem_y
for idy, y in enumerate(range(yi, yf, celula_y)):
if (y + celula_y) > yf:
break
buffer = int(celula_x / 2) if (alternada and idy % 2) else 0
xi = margem_x - buffer
xf = py5.width - margem_x
for x in range(xi, xf, celula_x):
pontos.append((x, y))
return pontos
def centro_celula(x0: int, y0: int, largura: int, altura: int) -> tuple[float, float]:
"""Calcula o centro de uma célula da grade."""
x = x0 + (largura / 2)
y = y0 + (altura / 2)
return x, y
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA)
py5.color_mode(py5.HSB, 160, 100, 100)
py5.background(0, 80, 20)
py5.ellipse_mode(py5.CENTER)
margem_x = -20
margem_y = -20
largura = 41
altura = 41
grade = cria_grade(margem_x, margem_y, largura, altura, True)
py5.stroke_weight(2)
for x, y in grade:
h = py5.random_int(120, 150)
s = py5.random_int(60, 70)
b = py5.random_int(40, 70)
py5.fill(h, s, b)
s -= 30
py5.stroke(h, s, b)
x, y = centro_celula(x, y, largura, altura)
escala_x = py5.random(0.7, 0.9)
escala_y = py5.random(0.7, 0.9)
angulo = py5.random_int(-90, 90)
forma = py5.create_shape(
py5.ELLIPSE, 0, 0, largura * escala_x, altura * escala_y
)
forma.rotate(py5.radians(angulo))
py5.shape(forma, x, y)
helpers.write_legend(sketch=sketch, cor="#FFF")
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()