Boids flock

Explore separation, alignment and cohesion in a reproducible three-dimensional flock.

About this tool

This is a discrete, three-dimensional steering model inspired by Reynolds' separation, alignment and cohesion behaviours. Coordinates are arbitrary model length units, not a calibrated animal or fluid simulation. There are no obstacles, targets, collisions or physical force laws.

One tick. All boids read the same old state. Neighbours lie within the selected radius, including its boundary. The cube wraps on every axis with period 8.4; positions are in [−4.2, 4.2). Neighbour distances and cohesion use the shortest periodic displacement δ. A boid just across a wrapping face can therefore be a close neighbour.

Separation S is the sum of −δ/|δ| over neighbours with 0 < |δ| < 0.35 × radius. It is not averaged, so a dense neighbourhood can exert more steering. Alignment A is the mean neighbour velocity minus the boid's own velocity. Cohesion C is the mean periodic displacement to neighbours. With no neighbours all three are zero. Coincident boids contribute zero separation but still count for alignment and cohesion; no random kick is added.

The update is v′ = cap(v + separation × S + alignment × A + cohesion × C), followed by x′ = wrap(x + 0.04 × v′). The cap limits speed to the chosen maximum. The coefficients apply once per 40 ms tick; they are not continuous-time force constants. The table shows the unweighted components for the next tick. Mean speed is the arithmetic mean of individual speeds.

Reproducibility and controls. A 32-bit seed initializes an LCG with s = (1664525 × s + 1013904223) mod 2³² and u = s / 2³². Six draws per boid set x/y/z to (u−0.5) × 4.2 × 1.6 and vx/vy/vz to (u−0.5) × 2; initial velocity is capped too. Seed 0 is valid. This generator is for repeatable examples, not cryptography.

Initialize prepares time zero and pauses. Run resumes the current state; Pause discards partial tick time. One step first pauses and advances exactly 0.04 s. Reset removes the flock but keeps the inputs. Any parameter edit invalidates the old result. Hidden pages pause automatically. The real-time scheduler accepts at most 250 ms per frame, discarding longer delays rather than making a large catch-up jump. The current flock and selection remain paused during navigation in this session. A full reload restores only valid parameters and requires explicit initialization again.

Views. The 3D cones point along velocity; a stationary boid is a dot. Drag to orbit and hold Ctrl or ⌘ while using the wheel to zoom; an ordinary wheel scrolls the page. Without WebGL, the same 3D state is shown in a fixed isometric SVG projection. Both views mark the selected boid with a ring. Symbol length does not indicate speed; a velocity perpendicular to the projection plane appears as a dot. Projection overlap does not imply that boids occupy the same 3D position.

Conceptual source: Craig Reynolds: Boids. The exact weights, radius, periodic boundary and fixed-tick rule above are this tool's specified variant, not a uniquely prescribed Boids formula.