A plain Canvas2D companion to the WebGL version: a swarm of balls bounces and collides inside a box, each impact resolved with the same impulse-based collision response used in physics engines and games.
j = -(1 + e)(v_rel . n) / (1/m1 + 1/m2) — j is the impulse magnitude, e the restitution, v_rel the relative velocity, n the unit contact normal, and m1, m2 the two masses. Velocities update as v1 += j*n/m1 and v2 -= j*n/m2.
The same impulse-momentum physics as the 3D version, rendered on a plain Canvas2D surface: total momentum stays conserved regardless of restitution e, while kinetic energy drops as e falls from 1 (elastic) to 0 (inelastic).
Drag Restitution (e) between 0 and 1, change the Mass ratio for asymmetric velocity exchanges, add Gravity for pile-ups, or drag a ball with the mouse.