Three rules, three hundred birds, zero brains
Murmur is a live flocking simulation you can poke: drag three sliders and watch hundreds of dumb agents organize themselves into something that looks alive.
A starling murmuration looks choreographed. Thousands of birds wheel and fold like one animal, and your brain insists somebody must be in charge. Nobody is. In 1986, Craig Reynolds showed you can fake the whole spectacle with three rules that each bird follows locally, looking only at its nearest neighbors:
- Separation: don't crowd me.
- Alignment: fly roughly the way my neighbors fly.
- Cohesion: drift toward the middle of my group.
That's it. No leader, no plan, no global view. Flocking is what those rules add up to, and it's still one of the cleanest demonstrations of emergent behavior in computer science.
A demo you can actually poke
Murmur is my version: a couple hundred boids on an HTML5 canvas, no frameworks, no build step, nothing to install. What makes it worth shipping when boids demos already exist is that most of them are locked boxes: a video, a screenshot, or a simulation with no knobs. The whole point of boids is cause and effect, and you only feel that with your hand on the dials.
So everything is a slider. Crank separation and the flock explodes into a nervous gas. Kill alignment and you get a mosquito swarm, all cohesion and no direction. Push cohesion to the max and the birds collapse into tight, orbiting blobs. There are presets ("tight schooling fish," "loose starlings," "chaotic swarm") if you want the good configurations without the fiddling, and a debug overlay that draws each boid's perception radius and velocity vector, which turns the magic trick transparent.
You're in the simulation too: click to attract the flock, right-click to scatter it, or drop obstacles it has to stream around.
The boring trick that keeps it smooth
The naive boids loop is O(n²): every bird checks every other bird, every frame. At 300 boids that's 90,000 distance checks per frame, and your laptop fan becomes the loudest thing in the room. Murmur uses the standard fix, a spatial grid: the canvas is diced into cells, each boid registers in its cell, and neighbor queries only look at adjacent cells. Same behavior, a tiny fraction of the work, smooth at flock sizes that would choke the naive version.
The honest footnote: the elegance of boids is also its limit. Real starlings respond to a fixed number of neighbors (about seven, per the Rome murmuration studies), not a fixed radius, and they have momentum, wind, and a hawk problem. Murmur is the textbook model, tuned to feel good rather than to publish papers. That's the right scope for a toy you open in a browser tab.
Try it
Open it, pick the "loose starlings" preset, then slowly drag alignment to zero and back while you watch. That one slider, moving through a phase change, is the best sixty seconds of the whole thing.
This post is part of the build log: every app my automated factory ships gets written up here, honestly. Browse everything at apps.charliekrug.com, or subscribe via RSS. Comments are open below.
Loading comments…