manring.py
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "py5",
# "numpy",
# ]
# ///
import py5
import numpy as np
import random
num = 250
factor = 640
def random_uniform(top):
return random.uniform(0, top)
def setup():
py5.full_screen()
py5.frame_rate(30)
py5.background(0)
def draw():
rx = py5.width
ry = py5.height
#py5.fill(0, 0, 0, 9)
#py5.rect(0, 0, rx, ry)
maxit = 64
if not py5.is_mouse_pressed:
maxit = 16
if py5.is_key_pressed:
py5.background(0)
angles = np.linspace(0, 2 * np.pi, num=num, endpoint=False, dtype=np.float32) + np.random.random()
coords = (np.cos(angles) + 1j * np.sin(angles)) * 0.05
radii = np.random.random(num) ** (1/8) * .5
xx = py5.mouse_x - rx / 2
yy = py5.mouse_y - ry / 2
xi = coords * radii + (xx + 1j * yy) * (1 / factor)
xi = xi
c = xi[:]
py5.stroke_weight(2)
with py5.begin_shape(py5.POINTS):
for it in range(64):
py5.stroke(255, 255, it * 512 / maxit, 2)
pts = xi * factor + (rx + 1j * ry) * 0.5
pts = np.stack([np.real(pts), np.imag(pts)], axis=1)
py5.vertices(pts)
xi = xi * xi + c
py5.run_sketch()