-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path__main__.py
125 lines (108 loc) · 2.81 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""2025-01-20
Generative Architecture
Casas, casas e mais casas
png
Sketch,py5,CreativeCoding,genuary,genuary2025,genuary20
"""
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
LARGURA = 80
ALTURA = 80
PALETA = [
[
(150, 100, 50),
(200, 50, 50),
(100, 50, 0),
(200, 200, 255),
],
[
(150, 80, 75),
(200, 50, 50),
(100, 50, 0),
(200, 200, 255),
],
[
(150, 90, 120),
(200, 50, 50),
(100, 50, 0),
(200, 200, 255),
],
]
PROFUNDIDADE = 5
ELEMENTOS = [
{
"pos": (0, 0, 0),
"cor": 0,
"func": py5.box,
"dimensoes": (160, 140, 180),
},
{
"pos": (0, 25, 101),
"cor": 2,
"func": py5.box,
"dimensoes": (40, 80, PROFUNDIDADE),
},
{
"pos": (-60, -20, 101),
"cor": 3,
"func": py5.box,
"dimensoes": (40, 40, PROFUNDIDADE),
},
{
"pos": (-80, 0, 0),
"cor": 3,
"func": py5.box,
"dimensoes": (PROFUNDIDADE, 80, 100),
},
{
"pos": (0, -70, 0),
"forma": py5.TRIANGLES,
"cor": 1,
"lados": [
[(-110, 0, 110), (110, 0, 110), (0, -60, 0)],
[(-110, 0, -110), (110, 0, -110), (0, -60, 0)],
[(-110, 0, 110), (-110, 0, -110), (0, -60, 0)],
[(110, 0, 110), (110, 0, -110), (0, -60, 0)],
],
},
]
def desenha_casa():
for elemento in ELEMENTOS:
paleta = py5.random_choice(PALETA)
with py5.push_matrix():
py5.translate(*elemento["pos"])
cor = paleta[elemento["cor"]]
py5.fill(*cor)
if func := elemento.get("func"):
func(*elemento["dimensoes"])
elif forma := elemento.get("forma"):
lados = elemento.get("lados")
with py5.begin_shape(forma):
for lado in lados:
for vertice in lado:
py5.vertex(*vertice)
def setup():
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.background(0)
py5.lights()
passo_x = 400
for idy, y in enumerate(range(-2000, 2400, 400)):
for xb in range(-2000, 2400, passo_x):
x = xb if idy % 2 else xb + passo_x // 2
with py5.push_matrix():
py5.translate(x, y, -2500)
py5.rotate_x(py5.radians(-25))
py5.rotate_y(py5.QUARTER_PI)
desenha_casa()
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()