TypologySienna Chen
MotionLightweight

Flocking & boids

Birds and fish that move as a group.

Birds, fish and crowds that move as a group from three simple rules: keep apart, go the same way, stay together. Add a cursor as a predator and the flock scatters.

Breaks when
O(n²) neighbour search past ~2k agents
Also called
boids, swarm, steering behaviours

Prompts

Flock that reacts to the pointer
Canvas 2D boids: 400 agents with a uniform spatial grid (cell = perception radius 60 px), separation 1.6, alignment 1.0, cohesion 0.9, max speed 3 px/frame, max force 0.08, edge wrapping. The pointer is a predator with a 150 px flee radius; clicking scatters the flock. Draw each boid as a tapered triangle along its velocity; highlight one and draw its radius and three force vectors for teaching.
GPU boids in Three.js
Port the flock to GPGPU with GPUComputationRenderer (position and velocity textures, 128×128 = 16,384 boids), each boid sampling its neighbours by looping the texture with a stride (cheap approximation), rendered as instanced cones oriented by velocity. Add a target attractor moving on a Lissajous path.
3D fish school
A 3D school of 600 fish in Three.js: boids in a bounding sphere with a soft return force, a slight downward gravity, tail-wag driven by speed in the vertex shader, and a predator sphere on the pointer ray. Use InstancedMesh and a spatial hash on the CPU.

Related

Resources · 2