"""2024-09-02
Fraturas Circulares 03
Inspirado por @[email protected], implementa um círculo fraturado em pequenos segmentos
png
Sketch,py5,CreativeCoding
"""
from collections import deque
from copy import deepcopy
import numpy as np
import py5
from utils import helpers
sketch = helpers.info_for_sketch(__file__, __doc__)
grade = None
tijolos = None
MARGEM_X = 0
MARGEM_Y = 0
PALETA = deque(
[
"#7ec0e0",
"#1c8eaf",
"#032035",
"#fdaa08",
"#f87109",
]
)
def gera_grade(
x0: int, y0: int, x1: int, y1: int, n_colunas: int, n_linhas: int
) -> tuple[list, deque]:
tam_paleta = len(PALETA)
altura = int((y1 - y0) / n_linhas)
largura = int((x1 - x0) / n_colunas)
y_ = np.linspace(y0, y1, num=n_linhas, endpoint=False)
x_ = np.linspace(x0, x1, num=n_colunas, endpoint=False)
grade = []
tijolos = deque()
for idy, y in enumerate(y_):
for idx, x in enumerate(x_):
paleta = deepcopy(PALETA)
id_cor = (idx + idy) % tam_paleta
paleta.rotate(-id_cor)
fundo = paleta.pop()
pg = py5.create_graphics(largura, altura, py5.P3D)
pg.begin_draw()
pg.background(fundo)
for iidx, diametro in enumerate(range(760, 5, -30)):
pg.stroke(paleta[iidx % (tam_paleta - 1)])
pg.stroke_weight(30)
x_c = -x + py5.random_int(-1, 1)
y_c = -y + py5.random_int(-1, 1)
pg.circle(x_c, y_c, diametro)
pg.end_draw()
grade.append((x, y))
tijolos.append(pg)
return grade, tijolos
def setup():
global grade, tijolos
py5.size(helpers.LARGURA, helpers.ALTURA, py5.P3D)
py5.background(0)
meio_x = py5.width / 2
meio_y = py5.height / 2
grade, tijolos = gera_grade(-meio_x, -meio_y, meio_x, meio_y, 10, 10)
def draw():
py5.background(0)
frame = py5.frame_count
meio_x = py5.width / 2
meio_y = py5.height / 2
if frame % 100 == 99:
tijolos.rotate(1)
with py5.push_matrix():
py5.translate(meio_x, meio_y)
for idx, (x, y) in enumerate(grade):
pg = tijolos[idx]
py5.image(pg, x, y)
helpers.write_legend(sketch=sketch, frame="#7ec0e0")
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()