Bird Flocking Lab
Nothing to install. It opens straight into a flying flock. Drag to orbit, press 1–9 to ride a bird, or H to watch from the beach.

A browser-based physics lab for studying how pelican flocks fly: how individual birds generate thrust from flapping, how they save energy by drafting off one another, and how formations like the V form, hold together, and reorganize.
The whole lab is a single self-contained HTML file built on three.js. Run it live, or open index.html locally in any browser; nothing needs installing.
Why this exists
This is the latest of several attempts I've made over the years to simulate bird flight. Earlier pieces: pelicans, a Processing flocking sim, and springs_and_arms, a workbench for articulated wing joints.
Classic Boids gets you convincing flocks from three local rules, but it cheats on the thing that matters most for formation flight: propulsion. A boid can step on the gas whenever it likes. A real bird has to pay for every bit of speed and every turn with muscle work, and that cost is the whole reason pelicans and geese fly in Vs: a bird sitting in the wingtip upwash of the bird ahead flies more cheaply.
So the goal here is to build the flock up from honest single-bird physics:
- Thrust has to come from the wing motion. It isn't added as a force.
- Drafting has to come from a wake model. The benefit of flying behind another bird should follow from the physics.
- Formation behavior should emerge from individual birds responding to their own state (fatigue, airflow, neighbors) rather than from a choreographer placing birds in slots.
What's simulated
Single-bird aerodynamics (blade-element / strip theory)
- Each wing is an articulated two-segment limb (inner arm plus outer hand) split into spanwise strips. Each strip computes its own local airflow (body motion, rotation, flapping velocity, wind, and wake) and its own lift and drag.
- Forward thrust emerges from the plunging downstroke (the Knoller–Betz effect). The wing folds at the elbow and wrist on the upstroke, which cuts upstroke drag and inertia.
- Per-segment angle of attack, feathering, wingtip-feather splay, and ground effect.
- Muscle-driven mode: the pectoralis and supracoracoideus are torque-limited by strength, length–tension, and Hill force–velocity curves. A bird that is too weak, or one with a rigid wing, can't sustain its wingbeat.
- Mass and bone thickness, head/tail mass distribution, a tail stabilizer, and active pitch/roll stabilization reflexes. Set the reflex gain to 0 to see the raw phugoid.
Flock
- Self-organizing formation: no slots, arms, or assigned leader. Each bird follows a handful of local rules (see How the formation emerges).
- Wingtip-vortex wake model: a bird outboard of the tip of the bird ahead gets upwash (a lift bonus), and a bird inboard of it gets downwash. Near the water, mirror-image vortices partly cancel it.
- Momentum slipstream: directly behind another bird is a low-drag channel of co-moving air.
- Intermittent flap-and-glide flight: each bird decides beat by beat whether to flap or coast.
- Surface skimming: the flock periodically drops to ride ground effect just above the water, as pelicans do working a surf line.
- Fatigue: flapping harder than a bird's sustainable power builds fatigue, which weakens its flight muscles and lowers the pace it wants to fly. Birds differ in fitness and preferred pace.
- Coastline following, gusty turbulent wind, and headwind and crosswind.
Fishing (v23)
- Fish schools show up on the water: a dark patch over a bait ball, silver fish milling and jumping, small boils at the surface, a ring, and a label with how many fish are left and how many pelicans are working it. They turn up ahead of the flock on their own, or you can click the water to drop one.
- Going fishing: a bird hungrier than 40% that sees a school within 150 m, or sees another bird fishing one, leaves the flock. A yellow line shows what it spotted. It circles about 13 m up in a left-hand orbit, then turns in and lines up a dive, aiming off to one side because its roll-in carries it left. Each bird learns where its own dives land.
- The plunge dive: it rolls left past vertical and pulls its nose down, sweeps its wings back and lifts them into a V over its back, then folds them flat in the last couple of metres and hits the water as an arrow. The tuck changes the real wing geometry in the aero model, so the lift genuinely goes away and the fall is ballistic. Dives from about 13 m hit the water at about 16.5 m/s (37 mph), 60–80° steep, close to the PBS footage (40 mph from about 40 ft).
- In the water: the impact makes it gulp air into its air sacs, so it pops back up within about a second from about 1 m down. Then it drains its pouch (bill down), swallows (head back), and bobs facing into the wind.
- Takeoff from the water: it flaps hard with the beat raised and runs on the surface with its feet, until its wings carry enough to break the water's grip. That takes about 3 s (2–4 s) and 11–30 m, lifting off at about 9–12 m/s.
- Full (hunger below 25%; birds start with different appetites, so it takes 1–3 fish), it stops fishing and climbs back up to the flock, even while others are still at it, so the flock breaks up. Hunger slowly comes back.
Fishing (v24)
- Scouting: a bird that finds a new school circles it for a couple of laps (1.5–2.5, the Scouting laps slider) before its first dive.
- Pods: a school is 5–8 pods of fish milling inside it. Each pod comes up to feed at the surface (silver fish, boiling water) for 8–18 s, then sinks out of reach (a dim blue glint) for 4–12 s.
- Diving on a chance: a circling bird turns in only when a pod is up at the surface ahead of it and inside its turn. It prefers pods that have just come up, and leads the pod by where it will be at impact. While it lines up and dives it has that pod to itself for a couple of seconds. The strike scares the pod down, and if the pod sinks while a bird lines up, the bird goes round again. So the dives come one at a time as the fish show, and about 3 in 4 land a fish.
- On the water, each bird faces its own way and paddles slowly about, then takes off roughly into the wind.
- Scenery: timber piers on pilings with planked decks and railings, groves of trees and bushes along the shore, a sun in the sky (ahead of the flock, about 40° up; the bird shadows on the sea are cast from it), and fair-weather cumulus clouds.
Coming and going (v25): the flock isn't a closed club. About every 45 s a bird drops out (never the lead, and never from a flock of 6 or fewer). Three in four glide down to rest on the water beside a pier or just off the beach; the rest head off out to sea. Birds resting along the coast ahead (two at the start) take off and tag on when a flock passes, after resting at least 20 s. A bird left out of sight behind comes back as a fresh bird resting somewhere ahead. So the flock grows and shrinks. Birds come and go turns it off; with it off, seeded runs replay v24 exactly.
The coast (v25): the sea has sharper wave crests with flat troughs, whitecaps on the highest crests, swell that steepens and breaks into lines of white water as it rolls toward the beach, foam running up the sand, and paler shallows. Lifeguard towers stand on the beach and boats (sailboats and small fishing boats) ride at anchor 100–200 m offshore, well clear of the flock.
Different birds, the cliffs and a calmer camera (v29): the birds are no longer clones. Males run about 3% longer and 10% heavier than females, every bird differs a little more (about ±6% in wingspan and ±18% in weight overall), and about one bird in seven is a first-year bird: grey-brown all over, a bit smaller and lighter. Size goes into the physics: a bird scaled up in length gets wings bigger by the square but weighs more by the cube, so big birds carry more weight on each square metre of wing, beat their wings a little slower, and shed stronger, wider wakes; slots in the V sit half of each neighbour's wake-span apart. Size differences and Young birds set how much (0 = identical birds). At cruise height, followers now take their rhythm from the bird ahead: each starts flapping about where it started and glides where it glided, so a wave of wingbeats runs back down the line, and it only beats harder or softer to keep its place (sitting a burst out when it's already ahead, breaking rhythm only when it falls 2 m or more out of place). Followers flap less, and their drafting costs less power. With an onshore breeze (Sea breeze on the bluffs), the air rising over the cliff edge is a band of ridge lift. Every couple of minutes (Cliff visits every) the flock swings in low toward the cliffs, lets the lift carry it up to the height where the rising air just about matches a gliding pelican's sink, and glides along the edge in a V narrowed to fit the lift band, mostly on outstretched wings; then it swings back out and comes down to the sea. Fishing and surface skims wait until it's back. Ground effect now only acts over the water. Two hang gliders fly the same lift along the cliffs, sinking through the air and carried up by the lift, holding a smoothed line along the edge and making an occasional U-turn out to sea. The camera now watches the middle of the flock rather than its lead (Camera watches the middle of the flock), so a change of lead no longer swings the view; pick a bird and it follows that bird as before. That middle is smoothed: birds fade in and out of it over a few seconds as they leave or rejoin the flock, and the aim moves with the flock and settles on a soft spring, so it never catches up in lurches. The wings are drawn as if they had mass: each joint follows the physics on a stiff spring, so the elbow opening at the top of the stroke, a burst starting, or a change to takeoff, circling or a dive is a quick smooth swing, not a one-frame snap. The bank is drawn the same way: a bird rolls into and out of its turns over about a quarter of a second instead of jumping 20–30° in a frame, and its tail twists along its length to help the roll (the physics itself is unchanged).
Pelican wings: hands, fingers and a flexible elbow (v34): the wings were stiff boards with an aeroplane's straight taper, and five rigid quills sprouting from one point at the wingtip. Now:
- Planform. The wing has a pelican's shape, in the physics and in the drawing alike. The arm keeps a broad, nearly even chord out to the wrist, with the secondaries' tips scalloped along its trailing edge, and the hand narrows to a slim tip. The total area is the same, so the wing loading is unchanged. It is a switch (
birdPlan; 0 = the old taper).
- Primaries. The hand is laid out as on a real pelican (Simons et al. 2011, J. Morphology, fig. 7B). Ten primaries root one after another along the hand bones, each at a slant: the inner ones point back and make the hand's trailing edge, and the outer ones point out past the bones, part into fingers at the tip, and run a little past it. Coverts hide their bases, so from above only the free outer parts show dark.
- Feather flex. The long primaries are springy. Each bends along its length, driven by a damped spring on the hand: when the arm stops at the bottom of the downstroke the tips carry on curling down, and as the downstroke starts from the top they bend up. This is drawn only, with a "Primary feather flex" slider (0 = rigid).
- Arm bones. The wing has a pelican's skeleton: a humerus from the shoulder to the elbow (47% of the arm), the radius and ulna from the elbow to the wrist, and the hand (the fused carpometacarpus and the finger bones). They pivot at the shoulder, the elbow and the wrist, in the physics and in the drawing. When the wing folds, the forearm swings forward at the elbow while the hand sweeps back at the wrist, linked as in a real wing ("Elbow-wrist link"), and the forearm's feathers bunch up, so its area drops by up to a quarter. The fingers give a little, so the outer primaries fan out a bit more on a fold. The arm is now 55% of the half-span instead of 42%, as on a California brown pelican, and
anatomy 0 restores the two-part wing.
- Elbow. The upstroke fold now follows each beat's own height, so a gentle cruising beat flexes the wing as a full one does (the fold used to be measured against the biggest possible beat, so cruising wings barely bent). The elbow also rests a little bent while gliding and on the downstroke of a gentle beat: 14 degrees at cruise pace, more when flying fast, less on a hard beat. This is a "Resting elbow bend" slider (0 = the wing locks straight), and
wingFlex 0 restores v33's fold.
Over 8 seeds of 10 minutes, the new wing lowered the flock's flight power from 59.8 W to 54.0 W and fatigue from 0.46 to 0.34, and the V filled in with a clump less often (31% of the time instead of 43%). The longer arm first cost about 2.5 W, but the cause was not the fold: the arm was set at 8 degrees of incidence, and a longer arm put more area at that steep angle, so it dragged. At 6 degrees the long arm costs less than the old short arm did (54.0 W against 57.5 W). A short arm at 6 degrees would be about 1.3 W cheaper still, but it doesn't look like a pelican. The drawn body is about 20% smaller (drawing only), as a pelican's torso is about 0.5 m against a 2.3 m span.