Particle Life — Sixteen Numbers, Whole Ecologies
Sliders edit a 4x4 attraction matrix. 5,000 WebGL2 particles. Watch ecologies emerge from sixteen numbers — predator-prey loops, swarms, crystals.
What this is
Five thousand glowing particles in four colors drifting on a near-black canvas. A 4x4 grid of sliders on the right controls how each color attracts or repels each other color. Drag a slider, watch the ecology rearrange itself in real time. Click RANDOMIZE to roll a new universe; click SYMMETRIC to force matrix[a][b] = matrix[b][a] and the system stops chasing itself; pick a preset (predator-prey, crystal, swarm, snake, gas, orbit) to see canonical configurations. The current matrix is encoded into the URL hash, so a configuration you love becomes a permalink anyone can open.
Why this is mind-blowing
Sixteen signed numbers — that's the entire genome. Flip a single coefficient and a swarm becomes a crystal lattice; nudge another and predator-prey chains form where red chases green chases blue chases yellow chases red. The bistable force kernel (repulsive close, attractive mid-range) means clusters breathe instead of collapsing. It is the smallest possible specification of a world that actually feels alive — and you can fit the whole thing in a URL.
Single-file particle life simulator in WebGL2. Attraction matrix (4×4, signed coefficients between each color pair). 5,000 particles. Each tick, every particle is pushed/pulled by neighbors based on the matrix. Sliders to live-edit each cell of the matrix. Save/share configs as URL hash. Watch ecologies emerge from 16 numbers — predator-prey loops, swarms, crystals.
Paste this into Claude, Cursor, or Copilot. Change one thing that matters to you.
What I learned shipping it
- Bistable force kernels — repulsive at close range, attractive at mid range — are why clusters never collapse to a point. Without that band, particle life is just gravity.
- A flat 1D spatial hash with toroidal-wrap 3x3 neighbor scans gets you O(n) force evaluation in plain JS — fast enough for 5,000 particles at 60fps without GPU compute.
- Encode the matrix into the URL hash and every great configuration becomes a permalink — discovery is the loop.