# KD-Tree aware-rupture Clifford attractor # Perturb a,b,c,d ONLY when local density < THRESH (neighbors within R) import numpy as np, matplotlib.pyplot as plt from scipy.spatial import cKDTree # ---- knobs (qualia) ---- SEED = 369 N = 120_000 # total steps CADENCE = 300 # how often to check density / maybe mutate WINDOW = 5000 # recent points used to estimate local density R = 0.03 # neighbor radius (smaller => rarer ruptures) THRESH = 5 # mutate if neighbors < THRESH (gap) HARD = np.array([.05,.05,.02,.02]) # mutation gains for (a,b,c,d) MEM = 0.015 # breath memory (coherence) # ---- init ---- rng = np.random.default_rng(SEED) a,b,c,d = 1.22,-1.37,1.61,0.92 x=y=0.0 mu = np.zeros(2) pts = np.empty((N,2), dtype=np.float32) for i in range(N): xn = np.sin(a*y) + c*np.cos(a*x) yn = np.sin(b*x) + d*np.cos(b*y) pts[i] = (xn,yn) mu = (1-MEM)*mu + MEM*pts[i] x,y = xn,yn # every CADENCE steps, decide whether to mutate based on local density if i>WINDOW and i % CADENCE == 0: cloud = pts[i-WINDOW:i] # recent geometry only tree = cKDTree(cloud) # count neighbors of current point within radius R (exclude itself by using k>1) k = len(tree.query_ball_point(pts[i], r=R)) if k < THRESH: # GAP => aware rupture guided by breath direction + a little noise m = np.linalg.norm(mu) + 1e-9 dmu = mu / m jig = (rng.random(4)-0.5) a += HARD[0]*(dmu[0] + jig[0]) b += HARD[1]*(dmu[1] + jig[1]) c += HARD[2]*((dmu[0]-dmu[1]) + jig[2]) d += HARD[3]*((dmu[1]-dmu[0]) + jig[3]) mu *= 0.2 # partial forgetting so it stays alive # ---- render ---- plt.figure(figsize=(6.6,6.6)) plt.axis('off'); plt.gca().set_aspect('equal') plt.plot(pts[:,0], pts[:,1], ",k", alpha=0.15) plt.show()