About Boids

How a handful of simple rules create the illusion of a living school of fish.

What is Boids?

In 1986, computer scientist Craig Reynolds published a paper describing a program he called Boids — short for "bird-oids." The idea was deceptively simple: instead of choreographing a flock by hand, give each individual agent a few local rules and let collective behavior emerge on its own.

No agent knows the shape of the flock. No agent has a global plan. Each one only looks at its immediate neighbors and adjusts its velocity accordingly. The result looks organic because it is organic — the same process drives real schools of fish, flocks of starlings, and swarms of insects.

Want to see it step by step? The How Boids Work page walks through each rule with interactive diagrams.

The Three Rules

Separation — don't crowd your neighbors

If another boid gets too close, steer away from it. This prevents fish from colliding and keeps the school from collapsing into a single point.

Alignment — swim the way your neighbors swim

Average the velocities of nearby boids and nudge your own velocity toward that average. This is what makes a school move together in a coherent direction.

Cohesion — steer toward the group center

Find the average position of your neighbors and gently turn toward it. This pulls the school back together whenever individuals start to drift apart.

See each rule in action: How Boids Work has interactive demos where you can adjust radii and strengths and watch the behavior change in real time.

The playground simulates Blue Tang boids using all three rules, plus a solo Orangestripe Triggerfish that roams on a Bezier path — showing how a non-schooling fish moves differently even in the same environment.

The Sliders

The playground exposes eleven sliders and a set of visualization toggles. Drag a slider and the simulation responds immediately — no reload needed. Click the ? button in the panel header to show inline descriptions for every parameter.

Global

ParameterWhat it does
SIM_SPEED Simulation speed — a time-scale multiplier. All forces, velocities, and movements scale together, so the behavioral dynamics stay the same — they just happen faster. Useful for quickly seeing the effect of parameter changes.

School Behavior

Parameter What it does
SEP_R Separation radius — fish closer than this distance push each other away. Raise it and fish give each other a wider berth.
ALI_R Alignment radius — fish within this distance try to match each other's heading. Larger values mean each fish listens to a bigger slice of the school.
COH_R Cohesion radius — fish within this distance steer toward the group center. A large value pulls distant stragglers back into the school.
W_SEP Separation strength — how hard fish push away from close neighbors. Turn this up and the school spreads out; turn it down and fish tolerate being packed together.
W_ALI Alignment strength — how strongly fish match their neighbors' direction. High values produce a tight, disciplined school moving in lockstep.
W_COH Cohesion strength — how hard fish pull toward the group center. Raise this and the school clusters tightly; lower it and fish are free to wander.

Turn & Damping

Parameter What it does
TURN_TANG Tang turn rate — how quickly a Blue Tang rotates toward its target heading (radians per second). Higher = snappier turns; lower = fish drift lazily around corners.
TURN_TF Triggerfish turn rate — same idea for the solo Triggerfish on its Bezier path. Higher values keep it hugging the curve more tightly.
DAMP_Y Vertical damping — reduces the vertical component of boid acceleration. Lower values let fish bob up and down freely; higher values flatten the school into a more horizontal plane.
DAMP_Z Distance damping — reduces acceleration along the depth axis (toward/away from the camera). Lower values scatter fish through the full depth of the scene; higher values keep them in a shallower layer.
Open the Playground →

Visualization Tools

Below the sliders, three checkboxes let you peel back the presentation layer and see what the algorithm is actually doing.

Show fish

Enabled by default. Uncheck it and the 3D fish models are replaced by small arrowheads pointing in each boid's travel direction — the same markers used in the How Boids Work diagrams. This strips away visual clutter and makes it easier to track individual agents, especially when combined with the distance lines below.

Radius spheres & distances

This toggle draws color-coded lines between every pair of fish that are close enough to interact, plus wireframe spheres around each tang whose color and size match one of the three boid rules. Use the radio buttons to choose which rule's radius to visualize:

  • Separation spheres — show how close is "too close." Drag the separation radius slider while these are visible and watch the spheres grow or shrink, directly revealing how much personal space each fish demands.
  • Alignment spheres — show the zone where fish try to match headings. A bold yellow arrow also appears at the school's center, pointing in the average swimming direction. The arrow's size responds to the alignment strength slider — crank it up and the arrow grows, giving you an at-a-glance sense of how dominant alignment is in the current mix of forces. This arrow is a convenient shorthand for the whole school's heading — but keep in mind that in the actual simulation each fish computes its own local average from just the neighbors inside its alignment radius. Those per-fish vectors are generally similar but each a little different; that local-only information is what makes boid alignment emergent.
  • Cohesion spheres — show how far each fish looks when deciding where "the group" is. Each fish steers toward the center of whichever neighbors fall inside this radius. There's no extra overlay here because drawing each fish's individual target point would add visual noise without much insight — the spheres themselves already reveal who's pulling whom.

The distance lines use the same color logic:

  • Red — inside the separation radius (pushing apart)
  • Yellow — inside the alignment radius (matching headings)
  • Green — inside the cohesion radius (pulling together)
  • Orange — tang fleeing the triggerfish

Try adjusting a radius slider while viewing its matching sphere type — the spheres and line colors update in real time, making it easy to see exactly how each radius shapes the school's behavior.

Show floating title

Toggles the 3D "Boids Playground" title text on or off, giving a cleaner view of the school.

Other Resources

There are quite a few boids simulations on the web. One I particularly like is Daniel Huang's elegant and beautiful Boids Simulation. It's a 2D world with up to 5,000 boids that does a wonderful job of highlighting emergent patterns of behavior. I particularly like his toggle to "show vision areas," which are analogous to our spheres, and which create beautiful heatmaps — particularly when "change hues to indicate speed" is selected. And which help to show what's going on internally.

For this playground, I began with the schooling fish simulation on my homepage, and then layered in the vision areas — as spheres, vs. circles, in my 3D Playground. I am particularly interested in how the hard-limit (in or out) radius settings lead to "soft" and emergent behaviors as the individual fish cross in and out of each others' spheres, as indicated by the connection lines that switch on and off when the "Radius spheres & distances" box is checked. I also wanted to dig into how the three different radii (separation, alignment, and cohesion) operate individually and collectively, which the playgrond supports.

Following the Playground, I also developed a How it Works page that walks through the individual forces as well as their collective effects on individual boids, with embedded interactive demos for each.

In short: for larger-scale emergent behaviors, I highly recommend Daniel Huang's work. For a more granular "under-the-hood" view, I think this playground does a good job. I hope you enjoy it. And regardless, I hope you find the boids algorithm as fascinating as I do!

Credits

The 3D fish models are paid assets by Nyi Nyi Tun on Fab.com: