03 Computational study
WASM Simulation
Small rules, shared motion. A flock of 48 agents finds its way by keeping space, matching direction, and gathering around its neighbors.
Flocking field
Saved flock preview. Load the simulation to explore; it starts paused.
An even balance of spacing, alignment, and gathering.
Starts paused. Motion pauses outside the visible area and in hidden tabs. Press Play to resume.
How it works
Three local rules
Separation steers away from crowding. Alignment nudges agents toward their neighbors’ velocities. Cohesion draws them toward nearby companions. The style control changes the balance of separation and cohesion.
Rust owns the simulation
Rust stores every position and velocity, finds neighbors, combines steering forces, and updates the next state. Speed and elapsed time are bounded. Agents interact across the wrapped edges instead of hitting walls.
Why Rust/WASM here?
The repeated neighbor calculations and state updates stay together in a tested Rust model. JavaScript receives one packed set of positions and velocities per draw and paints the canvas. This small, capped flock demonstrates the boundary without claiming WASM is always faster.
Explore at your own pace
The buttons and explanations are ordinary HTML. Step forward advances one short interval, even with reduced motion. A saved SVG preview remains readable without JavaScript, canvas, or WebAssembly. Loading or runtime failures restore that preview.
Read the Rust simulation on GitHub Gist →
← Back to the Workshop