Skip to content

Instantly share code, notes, and snippets.

@jepler
Created November 24, 2025 01:50
Show Gist options
  • Select an option

  • Save jepler/bcace43835cd0ed508bf7c4d22e66765 to your computer and use it in GitHub Desktop.

Select an option

Save jepler/bcace43835cd0ed508bf7c4d22e66765 to your computer and use it in GitHub Desktop.
Iterate nearby points in mandelbrot set
# /// script
# requires-python = ">=3.14"
# dependencies = [
# "py5",
# "numpy",
# ]
# ///
import py5
import numpy as np
import random
angles= np.linspace(0, 2*np.pi, num=1000, endpoint=False)
coords = (np.cos(angles) + 1j * np.sin(angles)) * .2
def random_uniform(top):
return random.uniform(0, top)
def setup():
py5.size(640, 360)
py5.background(0)
def draw():
if not py5.is_mouse_pressed:
return
py5.background(0) #Erases at each iteration
xx = (py5.mouse_x - 320) * (8/640)
yy = (py5.mouse_y - 180) * (8/640)
xi = coords + (xx + 1j * yy)
xi = xi
c = xi[:]
py5.stroke_weight(3)
with py5.begin_shape(py5.POINTS):
for it in range(16):
py5.stroke(255, 255, it*16, 16-it)
pts = xi * 640/8 + (320 + 180j)
pts = np.stack([np.real(pts), np.imag(pts)], axis=1)
py5.vertices(pts)
xi = xi * xi + c
py5.run_sketch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment