-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
88 lines (69 loc) · 2.09 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
"""2024-08-09
Hotel 02
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()
with pg.push_matrix():
pg.translate(TAMANHO_X / 2, TAMANHO_Y / 2)
pg.rotate(angulo)
pg.background(165, 42, 42)
pg.stroke(255, 255, 255)
pg.stroke_weight(2)
pg.no_fill()
pg.ellipse_mode(py5.CENTER)
for d in range(5, TAMANHO_X * 2 - 5, 20):
pg.circle(TAMANHO_X / 2, TAMANHO_Y / 2, d)
pg.end_draw()
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(255, 255, 255)
pg.stroke_weight(2)
pg.ellipse_mode(py5.CENTER)
for d in range(-meio_x + 50, meio_y - 50, 50):
x = helpers.LARGURA - d
pg.line(x, 0, x, helpers.ALTURA)
pg.end_draw()
return pg
PADROES = {1: padrao_01, 2: padrao_02}
GRADE = [
(1, 0),
(2, 0),
(1, 90),
]
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.background(0, 0, 0)
for idy, y in enumerate(range(100, py5.height - 100, 100)):
for idx, x in enumerate(range(100, py5.width - 100, 100)):
index = (idy + idx) % len(GRADE)
func, graus = GRADE[index]
padrao = PADROES[func](py5.radians(graus))
py5.image(padrao, x, y)
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()