How to use it
Pick a preset and start poking it. Grab is the default tool: press on a shape, drag it and let go to throw it. The other tools build things: draw a box or a ball by dragging, draw a fixed line as a ramp or a shelf, pin a shape to whatever lies behind it, and connect two shapes (or a shape and the background) with a rod, a rope or a spring. Delete removes one shape or joint. Explode blasts nearby shapes away. Pause, Step and Slow motion help you study a fast collision, and Reset rebuilds the current preset.
Controls
- Mouse or touch: choose a tool, then press or drag on the scene. The page does not scroll while your finger is on the scene.
- Keyboard: G grab, B box, C ball, L line, P pin, R rod, O rope, S spring, X delete, E explode. With the scene focused, the arrow keys move a cursor (Shift for bigger steps), Enter starts and finishes an action and Escape cancels it. Space pauses, the period key steps and M toggles slow motion.
- Sliders: gravity from 0 to 20 m/s², friction and bounciness for every shape, stiffness and damping for every spring.
- Weight of new shapes: light, normal or heavy (0.3, 1 or 5 kg per square metre).
- Step advances the scene by 1/60 s. Slow motion runs at quarter speed with steps half as long.
How it works
Every shape is a rigid body with a position, an angle, a velocity and a spin. The engine repeats the same loop 120 times per simulated second. First it integrates: gravity changes each velocity, then each velocity moves its body. This order, called semi-implicit Euler, is not exact, but it is cheap and stable.
Then it looks for collisions. A broad phase sorts the bounding boxes of all shapes along the x-axis, so only neighbours are compared exactly. Two boxes are tested with the separating axis theorem: if their shadows on any of the four face directions do not overlap, they cannot touch. Otherwise the direction of smallest overlap is the contact normal, and clipping one edge against the other face gives up to two contact points.
At each contact point the engine applies an impulse, a sudden change of momentum, along the normal:
Here vn is the speed at which the two surfaces approach, e is the bounciness (coefficient of restitution), m and I are mass and moment of inertia, and r points from each centre of mass to the contact. With e = 0 the bodies stop approaching; with e = 1 they separate as fast as they came. Friction is a second impulse along the surface, limited by Coulomb’s law: |jt| ≤ μ·j.
Why stacks are hard. In a tower every contact depends on all the others: the bottom box carries the whole weight above it, yet each impulse is computed from one contact alone. So the engine sweeps over all contacts eight times per step (sequential impulses) and starts each step from the impulses of the previous one (warm starting). A separate correction pushes small overlaps apart without adding energy. Without these tricks a stack would sink, jitter or creep apart.
Constraints. Joints use the same machinery. A pin keeps two points together, a rod keeps a fixed distance and a rope pulls only when it is fully stretched. A spring follows Hooke’s law, F = −k·x, plus a damping force against the motion. Shapes that stay still for a while fall asleep and are skipped until something touches them.
Things to try
- Load Newton’s cradle: one ball in, one ball out. Then lower Bounciness to 0.5 and watch the swing die.
- Set Gravity to 0 and throw a box into the pyramid. Nothing falls; the shapes drift until they hit something.
- Build a pendulum: tie a ball to the background above it with a rod and pull it aside. Try a short rod and a long one.
- Hang a heavy ball on a spring and change stiffness and damping while it bounces.
- Set Friction to 0 under the pyramid, or yank a box out of the middle of a tower.
Frequently asked questions
Why do stacked boxes overlap by a hair?
The solver tolerates about 5 mm of overlap so that resting contacts do not flicker on and off. And with eight sweeps per step, a very tall stack is never perfectly rigid.
Is energy conserved?
Only in ideal cases, such as a pendulum on a rod or the frictionless, fully elastic cradle. Friction and collisions with bounciness below 1 remove kinetic energy, which a real object would turn into heat and sound. The Total energy readout adds height and stretched springs to the kinetic energy.
Why do slow impacts not bounce?
Below an approach speed of 0.5 m/s bounciness is switched off. Otherwise shapes resting under gravity would keep trembling instead of settling.
Can a fast shape pass through a thin line?
Occasionally. Shapes move in steps of 1/120 s, so a small, fast one can jump across a thin line. Speed is capped at 30 m/s to make this rare, and the outer walls are too thick to cross.
How many shapes can I add?
Up to 250 shapes and 200 joints. Shapes at rest are asleep and cost almost nothing.