-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path__main__.py
More file actions
170 lines (147 loc) · 4.88 KB
/
Copy path__main__.py
File metadata and controls
170 lines (147 loc) · 4.88 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""2026-01-09
Padrão de Curvas Dinâmicas 03
Curvas que reagem à posição do mouse, criando um padrão fluído e em movimento.
ericof.com|https://openprocessing.org/sketch/2699138
png
Sketch,py5,CreativeCoding
"""
from sketches.utils.draw import canvas
from sketches.utils.draw.cores.paletas import gera_paleta
from sketches.utils.helpers import sketches as helpers
import py5
sketch = helpers.info_for_sketch(__file__, __doc__)
num: float = 4.0
tnum: float = 24.0
mult: float = 1.0
start: float = 0.0
stretch: float = 5.0
lm: py5.Py5Vector = py5.Py5Vector(0, 0)
def setup():
global lm
py5.size(*helpers.DIMENSOES.external, py5.P3D)
py5.background("ivory")
py5.no_cursor()
def desenha_padroes(largura, altura, paleta, target_x: float = 0, target_y: float = 0):
global num, tnum, mult, start, stretch, lm
target = py5.Py5Vector(target_x, target_y)
lm = lm.lerp(target, 0.1)
target_stretch = py5.floor(py5.remap(py5.mouse_y, 0, py5.height, 0.2, 6))
stretch = py5.lerp(stretch, target_stretch, 0.1)
num = py5.lerp(num, tnum, 0.1)
mult = py5.lerp(mult, py5.remap(py5.mouse_x, 0, py5.width, 1, 4), 0.1)
start = py5.lerp(start, py5.remap(py5.mouse_y, 0, py5.width, -12, 12), 0.1)
# translucent fade
py5.no_stroke()
py5.fill(255, 255, 240, int(0.25 * 255))
py5.rect(0, 0, py5.width, py5.height)
# mouse marker
# py5.fill(0, 20)
# py5.ellipse(lm.x, lm.y, 20, 20)
with py5.push():
cor = paleta[0]
paleta.rotate(1)
py5.translate(largura / 2, altura / 2)
py5.scale(0.95)
py5.stroke(cor)
py5.no_fill()
py5.stroke_weight(2.1 * altura / 628)
n = int(num)
for i in range(n):
a = py5.PI + i * py5.TAU / n
# first pair (mirrored with scale(-1, 1))
with py5.push():
py5.rotate(a)
cor = paleta[0]
paleta.rotate(1)
py5.stroke(cor)
py5.curve(
-start * altura / 6,
-altura * stretch,
0,
altura / 48,
0,
altura / 2,
start * 3 * altura / 9,
3 * altura / 2,
)
py5.scale(-1, 1)
py5.curve(
-start * altura / 6,
-altura * stretch,
0,
altura / 48,
0,
altura / 2,
start * 3 * altura / 9,
3 * altura / 2,
)
# second pair (scaled by mult and -mult)
with py5.push():
py5.rotate(a)
with py5.push():
cor = paleta[0]
paleta.rotate(1)
py5.stroke(cor)
py5.scale(mult, 1)
py5.curve(
-start * altura / 6,
-altura * stretch,
0,
altura / 48,
0,
altura / 2,
start * 3 * altura / 9,
3 * altura / 2,
)
with py5.push():
cor = paleta[0]
paleta.rotate(1)
py5.stroke(cor)
py5.scale(-mult, 1)
py5.curve(
-start * altura / 6,
-altura * stretch,
0,
altura / 48,
0,
altura / 2,
start * 3 * altura / 9,
3 * altura / 2,
)
def draw():
py5.background("ivory")
quadrantes = [
(0, 0, gera_paleta("Warhol", True)),
(0, 400, gera_paleta("Navy-Orange", True)),
(400, 0, gera_paleta("mondrian", True)),
(400, 400, gera_paleta("brasil-03", True)),
]
for ix, iy, paleta in quadrantes:
xb, yb = helpers.DIMENSOES.pos_interno
x, y = xb + ix, yb + iy
largura, altura = 400, 400
with py5.push():
py5.translate(x, y, -10)
target_x, target_y = py5.mouse_x, py5.mouse_y
desenha_padroes(largura, altura, paleta, target_x, target_y)
py5.window_title(
f"Mouse: {int(lm.x), int(lm.y)} "
f"Num: {num:.2f} "
f"Mult: {mult:.2f} "
f"Stretch: {stretch:.2f}"
)
# Credits and go
cor_fundo = py5.color(0)
canvas.sketch_frame(
sketch, cor_fundo, "large_transparent_white", "transparent_white"
)
def key_pressed():
key = py5.key
if key == " ":
save_and_close()
def save_and_close():
py5.no_loop()
canvas.save_sketch_image(sketch)
py5.exit_sketch()
if __name__ == "__main__":
py5.run_sketch()