Toys · Study 100
Gravity Marbles
Forty-six marbles roll, collide and pile up in a tray. Your pointer sets which way is down, so you can pour them from corner to corner.
What you're looking at
Gravity points from the centre of the canvas toward your pointer, and gets stronger the further out you go. Each frame is split into three smaller steps. In each one the marbles move, bounce off the walls with some energy lost, and every overlapping pair is pushed apart and exchanges momentum along the line between their centres.
The idea behind it
Resolving collisions pair by pair like this is the core of most game physics engines. It is approximate, since a marble in a pile touches several others at once, but repeating the correction a few times per frame is enough to make a heap settle and hold its shape.
Try this
Move the pointer toward any edge or corner to tilt the tray that way. The centre is level.