Take one rule away.
Let a flock organise. Switch off alignment while it runs, then bring it back. Next try cohesion or separation. Watch both the pattern and the spacing trace.
FIELD NOTE 19 / THE SWARM LAB
A hundred small decisions. One extraordinary pattern.
Build a flock, shape a school, and discover how a group can move as if it has a mind of its own.
Appearance changes only the illustration. The same agents and rules keep running.
Opposite edges connect: an individual leaving one side re-enters the other. Neighbour sensing also crosses those edges. Trails show every third individual and the selected one; glyphs are enlarged for visibility.
SOMETHING CHANGES
Turn one individual, or send a moving threat through its neighbourhood. Only nearby agents respond directly.
The threat follows a prescribed 12-second path. Agents within 22 model lengths steer away; no animals are captured or removed.
ONE INDIVIDUAL’S WORLD
The selected individual has no view of the whole group. Its rules use only the neighbours shown here.
Waiting for the first neighbourhood.
Coloured arrows show the weighted steering contributions.
Cyan: sensed social neighbours. Coral: personal-space neighbours. Grey: nearby but excluded from the social rule. Arrows share a steering scale; they are not physical force measurements.
100% means matching headings. Low whole-group agreement can mean disorder, several flocks going different ways, or an organised circulation. Local agreement averages each individual with its sensed neighbours; isolated individuals are excluded.
Spacing is measured in model lengths using connected edges. “Very close” means the nearest individual is less than 1.2 lengths away. Separation is soft steering, so this model does not guarantee animal-to-animal collision avoidance. A vertical marker identifies the latest setting change or disturbance.
Observations update every quarter model second.
Running. All normal controls preserve model time and playback.
FOLLOW THE SCIENCE
A flock can turn, stretch and divide without every bird knowing its outline. A school can change direction even though each fish experiences only a small part of the group. The question is how individual responses add up to coordinated movement.
In this lab, no individual receives the group’s centre, average direction or a destination. Each updates its heading from local information. The plots measure collective behaviour afterwards; those measurements never steer the agents.
MAKE A PREDICTION FIRST
Let a flock organise. Switch off alignment while it runs, then bring it back. Next try cohesion or separation. Watch both the pattern and the spacing trace.
Choose the narrow passage, then send a passing threat through the school. Does the group divide or turn together? Remove the constraint and watch what persists.
Begin with scattered individuals and unrelated headings. Nobody knows a destination. Does directional agreement emerge? Raise uncertainty and see whether it survives.
Begin with all three social rules off. Switch them on one at a time without restarting. Compare the group before and after. The external constraints remain separate rules.
Separation discourages crowding, alignment promotes similar headings, and cohesion pulls an individual toward its neighbours’ local centre. Each tendency is simple. Together they can sustain coordinated motion, while changing their relative strength changes the pattern.
Craig Reynolds introduced Boids as a distributed behavioural animation model in 1987. This lab uses its central ideas with our own explicit two-dimensional update rules. A convincing resemblance is a useful hypothesis, not proof that an animal implements the same algorithm.
In range mode, a crowded region supplies more social neighbours. In nearest-few mode, attention is capped at a chosen number, provided those neighbours are visible and in range. Both approaches here use a finite sensing distance.
Ballerini and colleagues’ field study of starling flocks found evidence for interactions with approximately six or seven nearest neighbours, rather than everyone inside a fixed distance. That finding motivates the comparison; it is not a universal rule for birds or fish, and our range-limited option is not a reproduction of their model.
A school travelling in one direction has high polarisation. A circular mill may be highly organised even though opposite sides travel in opposite directions and the global average nearly cancels. Two separate aligned groups can also cancel each other.
Experiments on golden shiners by Tunstrøm and colleagues distinguished disordered swarms, travelling aligned groups and circulating mills. Their observations motivate measuring more than one property. This lab’s plots do not classify a biological state or guarantee that every observed state will arise under these teaching rules.
A passing threat directly repels only agents within its influence radius. Other individuals may turn after their neighbours turn. An obstacle adds another local steering signal and constrains the available paths. Neither of those external signals is the same as spontaneous social coordination.
Try a single 60° heading change with the threat absent, then try the moving threat with alignment disabled. The intervention changes one heading instantly; later responses follow the normal local rules. Neither outcome needs a designated leader.
P is the magnitude of the mean unit heading. Perfectly aligned individuals give P = 1. An isotropic finite sample generally has a small nonzero value, not exactly zero. Local agreement uses the same calculation for each individual plus its social neighbours, then averages over non-isolated individuals.
These are self-propelled agents. The model continually supplies their travel speed and changes their headings through behavioural rules. It does not conserve mechanical energy or momentum. Real birds and fish power motion metabolically and experience aerodynamic or hydrodynamic forces that are omitted here.
The domain is 160 × 100 model lengths. Opposite edges connect, making a periodic domain with no common attracting centre. Distances and cohesion displacements use the shortest periodic displacement. The illustration is a top-down plane; background light, wings and tails are decorative. Switching Birds/Fish changes only appearance. The explicitly labelled restarting trials also change the displayed rule settings and starting distribution.
Personal-space avoidance senses every neighbour closer than 3.2 lengths in all directions. Social neighbours must lie within the range control and a 270° forward field. Nearest-few mode keeps only the closest k candidates. Ties use stable agent IDs. Each timestep reads the same old state for every agent before any positions are replaced.
S sums personal-space neighbours; A and C use the sensed social neighbours. Missing neighbours give a zero contribution. cap₁ limits a vector’s length to one. The heading turns toward θ* with a 0.42-second response scale and a maximum deterministic turn rate of 3.2 rad/s. If u + g vanishes, the previous heading is retained. Exact coincident pairs get opposite deterministic separation directions.
Δt = 1/60 model second. ξ is a reproducible, independent standard-normal draw keyed by sample, agent ID and timestep; σ is the uncertainty control converted from degrees to radians per square-root second. The deterministic turn cap does not cap that diffusion increment. Position advances at the selected speed using the new heading. Model lengths and seconds are illustrative, not calibrated species units.
Turning one individual adds 60° to only that heading, preserving all positions and the clock. A passing threat starts near the selected individual and follows a prescribed 12-second path across the periodic world with a sinusoidal vertical offset. Agents within 22 lengths receive an outward steering contribution of magnitude 4(1 − d/22). The path is externally scripted; it does not hunt, pursue or capture.
The obstacle is a circle of radius 11 at (80,50). The passage uses two radius-28 circles at (80,14) and (80,86), leaving a 16-length opening between their inward edges. Their copies connect across the top and bottom. Agents sense the obstacle boundary at their current position and at a 0.7-second straight-ahead prediction, adding outward steering within eight lengths of the boundary.
If an endpoint still penetrates a solid obstacle, a geometric fallback projects it outside with a 0.15-length margin and reflects any inward heading component. This is a constraint safeguard, not a realistic contact behaviour. Adding obstacles can immediately displace trapped agents. Point agents have no hard mutual collision constraint, so very strong cohesion, weak separation or large disturbances can cause overlaps.
Normal controls preserve time, headings and positions except for explicit population changes, a single-agent turn and displacement from a newly added obstacle. Added agents start at reproducible scattered positions; removed agents are the most recently added. Restart and Restart this trial explicitly begin again while preserving Play/Pause. Hidden pages freeze. Reduced motion starts paused. Playback affects viewing speed only.
Metrics and chart samples update every 0.25 model second. Short trails retain 2.4 seconds. History retains the full observation with at most approximately 2,400 samples, halving sampling density when needed. At five model minutes, Continue extends the same state and history. A setting change can immediately change local-neighbour statistics even before anything moves. Polarisation alone does not prove cohesion, stability or information transfer.
We omit altitude/depth, animal learning, leadership, individual variation in response, occlusion, finite reaction delays, metabolism, flight and swimming mechanics, fluid wakes and empirical parameter fitting. Repeated samples help distinguish a reproducible effect from one starting arrangement. Neither preset is a population forecast or a validation against real animal tracks.