This simulation flies a swarm of up to 80 quadrotors across a 2D canvas, each steered by Craig Reynolds' classic Boids model. Every drone applies three local rules each frame: separation (a repulsion within 35 px), alignment (matching neighbours' average velocity within 70 px) and cohesion (drifting toward the local centroid within 110 px). These weighted steering forces are summed, clamped to a maximum force, integrated into velocity, and capped at a maximum speed.
The Drones slider sets the swarm size, while the Speed slider scales both the applied force and the speed ceiling. Four buttons switch the active formation: Flock gives a loose centre pull, while Circle, Grid and V-Shape assign each drone a target slot it is attracted toward. Clicking the canvas relocates the formation centre. Such decentralised swarm logic underpins real-world drone light shows, search-and-rescue grids and military formation flight.
What is a drone swarm simulation?
It is an interactive model in which many simple agents, here quadrotors, produce coordinated group motion without any central controller. Each drone follows only local rules based on its neighbours, yet the swarm as a whole flocks, circles or holds a formation. It demonstrates how complex collective behaviour emerges from simple individual interactions.
How do the drones decide where to fly?
Each frame, every drone scans the others and computes three steering forces: separation away from very close neighbours, alignment toward their average velocity, and cohesion toward their average position. A formation force toward an assigned slot is added on top. These are weighted, summed, clamped, and used to update velocity and position.
What are the three Boids rules?
Separation steers a drone away from neighbours within 35 px to avoid collisions. Alignment nudges it to match the mean heading of neighbours within 70 px. Cohesion pulls it toward the centroid of neighbours within 110 px. Together these were proposed by Craig Reynolds in 1986 to model flocking birds, or "boids".
The Drones slider sets how many quadrotors are in the swarm, from 5 to 80 in steps of 5. The Speed slider, ranging from 0.5x to 3.0x, multiplies the steering force applied each step and raises the maximum speed cap proportionally, so the whole swarm moves faster and reacts more sharply.
Flock applies only a weak pull toward the centre, letting Boids behaviour dominate. Circle arranges drones evenly around a ring of radius about 22% of the smaller screen dimension. Grid spreads them on a square lattice with 48 px spacing. V-Shape places one leader at the centre with two trailing arms, like migrating geese.
Clicking, or tapping on touch devices, moves the formation centre to that point. Because the formation targets and the flock's centre pull are all computed relative to this centre, the entire swarm immediately begins steering toward the new location, letting you herd the drones around the screen interactively.
Separation, alignment, cohesion and formation forces are each multiplied by fixed weights (3.0, 0.7, 0.25 and 0.35 respectively) and added together. The resulting vector is clamped to a maximum force of 0.45 before being scaled by the speed multiplier and added to velocity. Velocity itself is then capped at the maximum speed so drones never accelerate without bound.
It is a simplified 2D kinematic model, not a full flight-dynamics simulation. It ignores gravity, rotor thrust, drag, mass and three-dimensional motion, treating each drone as a point that follows steering forces. The swarm coordination logic, however, mirrors the local-rule algorithms genuinely used in real swarm control research.
Each drone stores its last 22 positions and draws fading line segments between them, giving a sense of motion and recent path. The background is also only partially cleared each frame, blending old frames slightly so motion appears smooth and persistent rather than flickering. These are purely visual effects and do not influence the physics.
Avg spd is the mean speed of all drones, measured in pixels per frame and refreshed every 20 frames. Spread is the larger of the swarm's horizontal and vertical extent in pixels, indicating how tightly packed or dispersed the group is. Watching these reveals how formations tighten or loosen the swarm over time.
Decentralised swarm control drives synchronised drone light shows, agricultural and survey fleets, and coordinated search-and-rescue sweeps. The same emergent principles appear in computer-generated crowds and animated flocks in films and games, and in robotics research on resilient, leaderless multi-robot teams that keep functioning if individual units fail.