Three Rules
or, how a flock decides without a leader
If you have ever stood at dusk and watched ten thousand starlings turn together over a field, you know there is something in that motion that does not feel right. The flock pivots as one. It banks as one, scatters and re-forms as one, and at no point does any single bird seem to be giving the orders. There is no boss-bird. There is no central plan. There is no chairman of the murmuration. And yet that murmuration manages to do something that, if you tried to write it as a piece of software with one bird in charge of all the others, you could not get to look right in fifty years of engineering.
So how do they do it?
The answer turned out to be embarrassing. In 1986, a computer graphics researcher named Craig Reynolds was trying to make CGI flocks look right for an animated short. He had been writing code where each bird had a script, where every wingbeat and bank was specified up front. The result looked like ten thousand puppets — choreographed, mechanical, dead. Real flocks do not look like that. So Reynolds tried something different. He stopped telling each bird where to go. Instead, he gave each bird three rules of thumb about its neighbors:
- Don’t crowd them. (Separation.)
- Try to fly in the same direction they are flying. (Alignment.)
- Try to stay near the middle of the group of them you can see. (Cohesion.)
That is the whole thing. There is no bird leader, no plan, no global coordinator, no overall map of where the flock should be heading. Each bird only knows what is within ten feet or so of it, and follows those three obvious local rules based on the neighbors it has. Run those rules in parallel for a couple thousand simulated birds, and you get a murmuration. The bird-on-bird-on-bird arithmetic adds up to the very thing that looked like it had to be a magic act.
Reynolds called these little simulated birds boids — pronounced like a Brooklyn accent for “birds.” He was having his fun. And once you see the boids work, you cannot look at the world quite the same way again, because once you have eyes for the trick, you start seeing it everywhere.
Schools of fish do this. Crowds at airports do this. Ants on a pheromone trail do something a lot like this with a slightly different rulebook. Cells migrating in a developing embryo do this. Termites building those four-meter African cathedrals do this. The pattern recurs in domain after domain, and the thing that is recurring is not the substance of the system — fish are not birds, ants are not crowds — but the architecture of the rules that produce the behavior. We are looking, to put it in software terms, at a design pattern of the universe. A particular way of getting a coordinated whole out of independent parts. Nature reaches for it whenever the job calls for one, and as far as anyone can tell, the job calls for one most of the time.
I wrote software for a living for the better part of my career, and the thing programmers learn early — usually painfully — is that you cannot specify the behavior of a complex system from the top down. You can try. You will fail. The systems that actually work, the ones that scale and adapt and don’t fall over the moment you push them into a situation their creator didn’t anticipate, are the ones where each piece does its small local job, and the global behavior is allowed to come out of all the small jobs interacting. You give the parts good local rules and you let the whole take care of itself. There really is no other way that works at scale. Top-down works on small things, like a recipe for a cake. Top-down does not work on big things — not on a city, not on a forest, not on a brain, not on an economy. Anyone who tells you it does is selling you something.
This pattern goes by several names depending on which discipline you are reading at the time. Self-organization. Decentralized coordination. Stigmergy (a particularly good word; the ants invented it). Bottom-up design. Emergence from local rules. I am going to mostly call it what an engineer would call it: a design pattern of the universe, and one of nature’s favorites. By the end of this page I will be arguing that this pattern is not just one way to make complex things; it is the only way the universe knows how to make anything genuinely complex. The reason your brain works, the reason your immune system works, the reason an economy works (when it works), the reason a forest works .. is that not one of them was designed top-down by a central authority. They are all flocks. Different flocks. Same pattern.
But this all rests on the claim that three little rules, run in parallel by two hundred independent agents, can really produce something as alive-looking as a murmuration of starlings. That is a lot to take on faith. So let us not take it on faith.
Below is a working flock of two hundred boids. The three rules are exposed as sliders, and so are a few other knobs — how far each bird can see, how fast they are allowed to go, how many of them are on the screen at once. Watch what changes. Watch what stays the same. There are some specific experiments to try at the end of the page, and I will cheat by telling you what to look for.
The Experiment
What each knob does
- Separation — how strongly each bird steers away from neighbors that have gotten too close. Distance-weighted: very close neighbors push much harder than just-within-range ones, so two flocks should not flow through each other.
- Alignment — how strongly each bird tries to match the heading of its visible neighbors. The "everyone facing the same way" force.
- Cohesion — how strongly each bird steers toward the center of its visible neighbors. The force that keeps a flock from dissolving.
- Coh range — how much farther cohesion looks than separation and alignment, as a multiplier of perception. With it set to 1, all three rules use the same radius and the flock either stays as one blob or breaks apart for good. With it greater than 1, cohesion reaches farther than alignment, so subgroups can drift apart, fly with their own headings for a while, and still feel the pull of the wider flock and merge back. This is what produces the splitting-and-merging behavior of real murmurations.
- Perception — how far each bird can see, in pixels. Larger = each bird considers more of the group; smaller = the flock fragments into local cliques.
- Max speed — the ceiling on how fast a bird can fly.
- Min speed — the floor on how fast a bird can fly. Real birds have a stall speed below which they lose lift and fall; our birds get this for free as a constraint. With Min speed near zero a bird can hover or stop, which is unrealistic; with it close to Max speed the flock is committed to motion.
- Flock size — how many birds are on the screen.
- Reaction — how quickly a bird responds to its own rules. 1.0 = instant. Lower values introduce a delay between sensing and steering, the way real animals have. The lag is a major reason wave-like ripples can propagate through a real flock; an instant-reaction simulation skips that whole phenomenon.
- Noise — small random perturbations to each bird’s motion every frame, standing in for air currents and individual idiosyncrasy. Without any noise, a flock can settle into a frozen synchronized state; with too much, the flock dissolves. There is a Goldilocks band.
The simulation is bounded — the canvas edges are the world’s edges. Birds turn back from them rather than wrapping around the screen. The predator influences boids within roughly 110 pixels, with a flee force that grows as it gets closer. Separation kicks in when neighbors are within about 45% of the perception radius; outside that they are merely seen, not fled.
Things to try:
Set all three rules to zero. The boids go nowhere — they drift in straight lines, indifferent to each other, like commuters who have never met. There is no flock here. There is barely a system.
Now turn ALIGNMENT all the way up, leave the others off. The boids end up pointing the same direction, like the world’s most boring parade. There is coordination, but there is no flock — they don’t stay together, they don’t move as a unit, they are synchronized loners.
Now turn COHESION up too. They start clumping. Now you have a flock-shaped blob.
Add SEPARATION. The blob loosens — they keep a polite distance, they don’t pile up. Now you have a murmuration. You did not design it. You just turned on the three rules.
Try setting PERCEPTION very small. The flock fragments — birds can only see their immediate neighbor, and the whole becomes a series of little gangs that occasionally collide. Try a huge perception radius — the flock collapses toward consensus, the murmuration becomes more like a thrown ball. Goldilocks lives somewhere in the middle.
Use the FLOCK SIZE slider to drop down to a single boid, then watch it. It is doing nothing interesting. It is just .. flying. Now ramp it back up to two hundred. The same rules, the same boid, the same arithmetic. The difference between not interesting and a murmuration is .. company.
Click anywhere on the canvas. The flock is briefly attracted to that point. Notice that no individual bird had to be told to come; the flock as a whole leans in, and then the flock as a whole leans out. The flock is the unit of behavior, even though no piece of code in this simulation knows the flock exists.
If you watch this for a few minutes you will start to feel something I can only describe as a click. The thing in front of you is alive in a particular sense — not biologically, not morally, but pattern-wise. It is doing the same thing the starlings are doing. Different substrate, same architecture. If you let yourself stay with that feeling, you have just felt one of the universe’s favorite tricks in your nervous system, where it belongs. Three local rules running in parallel, no leader, no plan, and a flock comes out the other side.