Afterglowscreensavers

Bouncing Balls Pit Screensaver

The Bouncing Balls Pit screensaver simulates a pit of colorful balls with real elastic-collision physics, bouncing endlessly off walls and each other. It is free, runs in your browser, and ESC exits.

Live preview

Bouncing Balls Pit screensaver — A pit of real physics-simulated balls, bouncing and colliding.

Press ESC to leave fullscreen. Settings are saved in your browser only.

How the Bouncing Balls Pit screensaver works

The saver simulates each ball's real position and velocity, updated every frame.

Balls bounce elastically off the screen edges and exchange momentum realistically when they collide with each other.

Gravity gently pulls balls downward, so they settle and jostle like a real ball pit.

The simulation runs indefinitely, with balls in constant, believable motion.

Elastic collisions and a pit of balls

The simulation rests on a simple idea from classical mechanics: when two bodies collide elastically, momentum and kinetic energy are both conserved. For two equal balls hitting head-on, that means they simply exchange velocities. For glancing impacts, only the part of each velocity along the line between the centres is exchanged, which is why balls scatter at angles. Hitting a wall reverses the component of velocity perpendicular to it.

Gravity adds a constant downward acceleration, and a real pit would lose energy to heat and sound at every impact. The coefficient of restitution captures that: it is the ratio of the relative speed of separation after a collision to the relative speed of approach before it, usually between 0 and 1. A value of 1 is a perfectly elastic collision with no kinetic energy lost, and 0 means the objects stick together. It describes a pair of colliding objects rather than a single ball.

Collision detection becomes the main computing challenge as the number of balls grows. Checking every pair of balls grows roughly with the square of their number, so simulations commonly divide space into a grid or tree and only test neighbours. Numeric error can also leave balls slightly overlapping, so simulations often nudge positions apart.

A worked example

Two balls collide head-on and rebound apart at real physically consistent angles, exactly as elastic-collision math predicts.

Settings & tips

Frequently asked questions

Is this real physics?
Yes — real elastic-collision and gravity simulation drives every ball's motion.
Is a key needed?
No — it is a pure local simulation.
Is it free?
Yes — free, no download, in your browser.
How many balls are there?
A moderate pit size tuned for smooth performance in any browser.
Why do the balls end up piled at the bottom?
Gravity pulls them down, and each bounce can lose some energy, so they gradually settle. A perfectly elastic world would keep bouncing indefinitely.
What is the coefficient of restitution?
It is the ratio of the relative speed of separation after a collision to the relative speed of approach before it. A value of 1 means a perfectly elastic bounce, and 0 means the objects stick together.
Why is simulating many balls expensive?
Every ball could hit every other, so naive pair checking grows quickly with the number of balls. Simulations reduce this by only testing nearby balls.

← All Classics screensavers