-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
73 lines (59 loc) · 1.7 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
"""2024-04-14
Circuíto I
Exercício de criação de um circuíto a partir de uma grade
png
Sketch,py5,CreativeCoding,grid
"""
import py5
from utils import helpers
from utils.draw import cria_grade
sketch = helpers.info_for_sketch(__file__, __doc__)
GRADE = None
LARGURA = 23
ALTURA = 23
def setup():
global GRADE
py5.size(helpers.LARGURA, helpers.ALTURA)
py5.frame_rate(1)
py5.color_mode(py5.HSB, 360, 100, 100)
py5.ellipse_mode(py5.CENTER)
py5.rect_mode(py5.CENTER)
margem_x = -20
margem_y = -30
GRADE = cria_grade(
py5.width, py5.height, margem_x, margem_y, LARGURA, ALTURA, False
)
py5.no_fill()
def draw():
py5.background(120, 0, 100)
py5.stroke_weight(3)
for x, y in GRADE:
h = py5.random_int(220, 250)
s = py5.random_int(0, 1)
b = py5.random_int(0, 1)
py5.stroke(h, s, b)
direcao = py5.random_int(3)
if direcao == 0:
coordenadas = (x, y, x + LARGURA, y + ALTURA)
elif direcao == 1:
coordenadas = (x, y + ALTURA, x + LARGURA, y)
elif direcao == 2:
coordenadas = (x, y, x + LARGURA, y + ALTURA)
elif direcao == 3:
coordenadas = (x, y, x, y + LARGURA)
py5.line(*coordenadas)
with py5.push_style():
py5.stroke_weight(1)
py5.fill(h, s, b)
py5.circle(coordenadas[2], coordenadas[3], LARGURA / 2)
helpers.write_legend(sketch=sketch, cor="#FFF", 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()