-
Notifications
You must be signed in to change notification settings - Fork 1
/
__main__.py
84 lines (71 loc) · 2.12 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
"""2024-01-22
Genuary 22 - Point - line - plane.
Animação da transformação de um ponto em uma linha, em um plano.
gif
Sketch,py5,CreativeCoding,genuary,genuary22
"""
import numpy as np
import py5
import py5_tools
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
POSICOES = []
QUADRADO = None
def setup():
global QUADRADO
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.color_mode(py5.HSB, 360, 100, 100)
lado = 200
meio_lado = lado / 2
xb = helpers.LARGURA / 4
x0 = xb - meio_lado
x1 = xb + meio_lado
yb = (helpers.ALTURA / 4) * 3
y0 = yb - meio_lado
y1 = yb + meio_lado
POSICOES.extend([(x1, y) for y in np.linspace(y1, y0, num=lado, endpoint=True)])
POSICOES.extend([(x, y0) for x in np.linspace(x1, x0, num=lado, endpoint=True)])
POSICOES.extend([(x0, y) for y in np.linspace(y0, y1, num=lado, endpoint=True)])
POSICOES.extend(
[(x0, y, x1, y) for y in np.linspace(y0, y1, num=lado, endpoint=True)]
)
QUADRADO = (x0, y0, x1, y1)
def draw():
py5.background(0)
frame = py5.frame_count
total = len(POSICOES)
idx = total - 1
angulo = 45
incompleto = frame <= total
if incompleto:
idx = (frame % total) - 1
angulo = py5.remap(idx, 0, total, 0, angulo)
py5.stroke_weight(5)
with py5.push_matrix():
py5.rotate_x(py5.radians(angulo))
py5.rotate_z(py5.radians(-(angulo / 2)))
for i in range(0, idx):
pos = POSICOES[i]
s, h = pos[:2]
h = py5.remap(h, 200, 600, 120, 240)
s = py5.remap(h, 200, 600, 80, 100)
py5.stroke(py5.color(h, s, 100))
func = py5.line if len(pos) == 4 else py5.point
func(*pos)
helpers.write_legend(sketch=sketch)
def key_pressed():
key = py5.key
if key == " ":
save_and_close()
def save_and_close():
py5.no_loop()
py5.exit_sketch()
if __name__ == "__main__":
py5_tools.animated_gif(
f"{sketch.path}/{sketch.day}.gif",
count=140,
period=0.1,
duration=0.01,
block=False,
)
py5.run_sketch()