Starling Murmuration
At dusk over European cities, hundreds of thousands of starlings gather into vast, fluid shapes that pulse, split, and reform. Unlike standard flocking models, real starlings use topological interaction — each bird tracks its nearest six or seven neighbors regardless of metric distance. The result is a flock that maintains cohesion even as it stretches and compresses, with turning waves that propagate at 20–40 m/s, three times faster than the birds fly.
Each bird → k nearest neighbors (topological, not metric)
Topological vs. metric interaction
Craig Reynolds’ original boids model (1987) uses a metric interaction rule: each agent responds to all neighbors within a fixed radius. This works beautifully for computer graphics, but it does not match what real starlings do. In 2008, Michele Ballerini and colleagues at the STARFLAG project analyzed 3D reconstructions of real starling flocks and discovered that each bird interacts with a fixed number of neighbors — approximately six to seven — regardless of how far away they are. This is a topological rule: what matters is not distance, but rank order of proximity. The distinction has profound consequences. Under a metric rule, when the flock expands and inter-bird distance grows, each bird has fewer neighbors, and the flock can fragment. Under a topological rule, each bird always has the same number of social contacts, so the flock maintains cohesion even when stretched thin. This simulation implements the topological rule: for each bird, we find its k nearest neighbors (default 7) and apply alignment, cohesion, and separation forces only to that set.
Why starlings murmurate
Despite decades of study, the purpose of murmuration remains debated. The leading hypotheses include: predator dilution — each individual starling reduces its chance of being caught by a raptor (typically a peregrine falcon) by hiding in a dense group, where the predator struggles to single out a target; information exchange — birds share knowledge about high-quality roosting sites by following experienced individuals to the roost; thermoregulation — large communal roosts retain warmth on cold winter nights; and social attraction — starlings are gregarious birds that simply prefer to be near conspecifics. The truth is probably some combination. What is clear is that the murmuration itself — the aerial display before roosting — intensifies dramatically when a peregrine is present, suggesting that predator defense is at least one important driver. Toggle the predator in the simulation above and watch how the flock splits, compresses, and reforms around the threat.
Scale-free correlations
In 2010, Andrea Cavagna and colleagues made a remarkable discovery: velocity fluctuations in starling flocks are scale-free. That is, correlated domains of birds changing direction together extend across the entire flock, regardless of flock size. In a flock of 500, correlations span the group. In a flock of 5,000, correlations still span the group. This is the hallmark of a system near a critical point — like a magnet at its Curie temperature or water at its critical point. At criticality, fluctuations have no characteristic length scale, which means the system is maximally responsive to perturbation. A predator attacking one edge creates a response that propagates across the entire flock almost instantaneously. If the flock were deep in the ordered phase (too rigid), it could not respond quickly enough. If it were in the disordered phase (too loose), the response would be local and weak. Poised at criticality, the flock achieves optimal collective responsiveness.
Compression waves
When a disturbance propagates through a murmuration — typically triggered by a peregrine dive — it travels as a compression wave, visible as a dark band sweeping across the flock (a region where birds are momentarily denser). Alessandro Attanasi and colleagues measured these waves in 2014 and found propagation speeds of 20–40 meters per second, roughly three times the flight speed of the birds themselves. The mechanism is anticipatory: each bird begins to react to the change in its neighbors’ heading before the turn is complete, so the signal outruns the movement. This is analogous to a compression wave in a spring (which travels faster than any individual coil moves) or a stadium wave (which travels faster than any individual stands and sits). The flock functions as a distributed sensory organ, detecting and broadcasting threats far faster than any individual bird could.
What this simulation models
This is a 2D simulation with topological neighbor selection. For each bird, we sort all other birds by distance and pick the k nearest. Alignment steers toward the average heading of those k neighbors. Cohesion steers toward their average position. Separation pushes away from any neighbor closer than a minimum distance. Birds are rendered as elongated shapes aligned with their velocity, so dense regions appear darker due to overlapping silhouettes — mimicking the view-angle density effect in real murmurations. The optional predator follows a looping path through the flock, and birds within a fear radius flee directly away from it, temporarily overriding their flocking rules. Real murmurations are three-dimensional, exhibit anisotropic interactions (birds pay more attention to lateral neighbors), and involve complex aerodynamics. But the essential qualitative behavior — fluid deformation, splitting, and re-coalescence around threats — emerges from the topological rule alone.