-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
110 lines (91 loc) · 2.33 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
"""2024-08-11
Hotel 04
Tentativa de recriação de padrão de carpete de um hotel.
png
Sketch,py5,CreativeCoding
"""
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
TAMANHO_X = 96
TAMANHO_Y = 96
def padrao_01(angulo: int = 0) -> py5.Py5Graphics:
pg = py5.create_graphics(TAMANHO_X, TAMANHO_Y, py5.P3D)
pg.begin_draw()
meio_x = TAMANHO_X // 2
meio_y = TAMANHO_Y // 2
with pg.push_matrix():
pg.translate(meio_x, meio_y)
pg.rotate(angulo)
pg.background(165, 42, 42)
pg.stroke(244, 164, 96)
pg.stroke_weight(2)
pg.no_fill()
pg.ellipse_mode(py5.CENTER)
for d in range(5, TAMANHO_X * 2 - 5, 20):
pg.circle(meio_x, meio_y, d)
pg.end_draw()
pg.rotate(-angulo)
return pg
def padrao_02(angulo: int = 0) -> py5.Py5Graphics:
pg = py5.create_graphics(TAMANHO_X, TAMANHO_Y, py5.P3D)
pg.begin_draw()
meio_x = TAMANHO_X // 2
meio_y = TAMANHO_Y // 2
with pg.push_matrix():
pg.translate(meio_x, meio_y)
pg.rotate(angulo)
pg.background(165, 42, 42)
pg.stroke(244, 164, 96)
pg.stroke_weight(2)
for x in range(-meio_x + 3, meio_x, 10):
pg.line(x, -meio_y, x, meio_y)
pg.end_draw()
pg.rotate(-angulo)
return pg
PADROES = {1: padrao_01, 2: padrao_02}
GRADE = [
# Primeira linha
(1, 0),
(2, 90),
(1, 180),
(1, 0),
(2, 90),
(1, 90),
# Segunda linha
(2, 0),
(1, 0),
(2, 90),
(1, 180),
(1, 0),
(1, 180),
# Terceira linha
(1, 270),
(1, 180),
(1, 0),
(2, 90),
(1, 180),
(1, 90),
]
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.background(0, 0, 0)
idx = 0
for y in range(100, py5.height - 100, 100):
for x in range(100, py5.width - 100, 100):
index = idx % len(GRADE)
func, graus = GRADE[index]
padrao = PADROES[func](py5.radians(graus))
py5.image(padrao, x, y)
idx += 1
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()