Firefly Swarm Dynamics (3D)

Hundreds of fireflies in a night meadow; each flash clock nudges its neighbours until the swarm blinks as one.

Switch to 2D

Presets

Playback

Swarm

Sight radius is how far a firefly can see a flash. Speed is how fast the swarm drifts; moving fireflies swap neighbours and spread the sync.

Flash clock

Each firefly has its own natural rate. A bigger spread makes synchrony harder because fireflies must overcome their differences.

Coupling

K is how strongly a firefly pulls its clock towards the average of the flashes it sees. Noise is random jitter of each clock.

Lantern

A flashing lantern pulls nearby fireflies. Set the pull above zero and tune the lantern period to the meadow period.

Drawing

Fireflies are drawn about ten times bigger than real ones so you can see them. These sliders do not change the physics.

Camera

Quality

Layers

Model checks

The science

What you are looking at

Every firefly is a tiny clock. Its phase theta runs from 0 to 2 pi once per flash period and it flashes when the phase passes zero. Left alone, each firefly has its own natural rate w_i, so the meadow blinks at random. A firefly that can see others nudges its clock towards theirs, and above a critical coupling thousands of independent clocks lock together. This is the Kuramoto model.

The equations

d theta_i / dt = w_i + (K / n_i) * sum_j sin(theta_j - theta_i) + F(d_i) sin(Omega t - theta_i) + noise

The sum runs over the n_i fireflies inside the sight radius of firefly i (a sphere in 3D, a disc in 2D). K is the coupling strength in rad/s. The last term is the lantern: a light that flashes with period 2 pi / Omega and pulls fireflies within its reach, with strength fading linearly with distance.

Synchrony is measured by the order parameter r e^(i psi) = (1/N) sum_j e^(i theta_j). It is about 1/sqrt(N) for random phases and 1 when everybody flashes together; psi is the mean phase.

Critical coupling

If every firefly saw every other one (all-to-all), the natural rates had a density g(w) and g were single-peaked, order would appear at K_c = 2 / (pi g(w0)). For Gaussian rates of width sigma this is K_c = 2 sigma sqrt(2 pi) / pi = 1.596 sigma; for Lorentzian rates of half-width gamma it is K_c = 2 gamma. Above it the order parameter solves r = K r * integral_(-pi/2)^(pi/2) cos^2(phi) g(K r sin phi) d phi, which for Lorentzian rates is exactly r = sqrt(1 - K_c / K). The yellow curve in the "r versus K" graph is this theory.

Locked and drifting fireflies

Two fireflies with rate difference dw and mutual coupling K obey d(phi)/dt = dw - 2K sin(phi). They lock at a fixed lag phi* = arcsin(dw / 2K) when |dw| <= 2K; otherwise the lag drifts at sqrt(dw^2 - 4K^2). In a crowd the same idea splits the population: fireflies whose natural rate is close to the mean lock to one common rate (the flat band in the "effective versus natural rate" graph), those in the tails keep drifting.

The lantern

A flashing lantern acts like one very loud neighbour. It can capture a firefly only if the firefly's rate is within the pull F of the lantern's rate (the Adler equation), so a lantern period far from the meadow's own period captures only a few fireflies near it.

Honest simplifications

  • Real fireflies such as Pteroptyx malaccae and Photinus carolinus are pulse-coupled: they reset or advance their internal clock when they see a flash (Buck and Buck 1968; Mirollo and Strogatz 1990). The smooth sin coupling here is the standard analytically tractable cousin. Both synchronise; the details of the transient differ.
  • Each firefly averages over the neighbours it sees. The theory curve is for all-to-all coupling, so with a small sight radius the simulation can lie below it and shows travelling waves and local patches instead.
  • Sight is a hard sphere with no obstacles, no line of sight and no flash brightness falloff. Fireflies fly as a persistent random walk in a 24 m wide box with reflecting edges and do not fly towards each other.
  • Fireflies are drawn about ten times larger than real ones (about 1.5 cm) and the flash period is a few seconds, much shorter than the 12 s of P. carolinus, so you can watch it.
  • The "mean-field simulation" points use 800 oscillators with quantile-spaced rates integrated for 45 simulated seconds, so they converge slowly right at K_c and differ by a few percent from the infinite-population theory.
What to try
  • Start random, then press "Gentle synchrony". Watch r(t) climb from about 0.05 towards the yellow theory line and the phase histogram collapse into one peak.
  • Find K_c. Drag the coupling slider slowly upwards in "Night begins": order appears near the orange line K_c in the "r versus K" graph.
  • Shrink the sight radius to about 2 m ("Local waves"): fireflies synchronise in patches and the order parameter stays below the all-to-all theory.
  • Increase the natural-rate spread and see K_c rise, the flat locked band in the last graph get narrower, and r fall.
  • Switch to Lorentzian rates. A few very fast or slow fireflies never lock, but the core synchronises at a lower K_c for the same width.
  • Lantern: set the pull to 1.6 and match its period to the meadow (2.0 s) to capture the whole area, then detune it to 3 s and see only the nearby fireflies follow it.
  • Click a firefly to track it: its sight sphere, the links to the fireflies it sees, and its dot on the phase circle are highlighted.
Loading Blender model...
Order parameter r(t) against the all-to-all theory
Order parameter r versus coupling K: theory and mean-field simulation
Flashes per second over the last 20 seconds
Phase histogram of the whole swarm
Phase circle: every firefly and the mean field
Effective versus natural rate: the locked band
Made with 🟠 Blender · Three.js