This project is read-only.

Gravity Ball Screen Saver


This is a simple screen saver that will mesmerize you while you watch two balls slowly come together, wondering if they’ll fall into a stable orbit or gravity boost to opposite sides of the screen. When a stable orbit forms, how long will it last? What will happen when that third ball gets too close?

The genesis of this program came to me while reading an article about Deep Space, specifically about the notion that after planets had formed around a star, it was possible that they may loose their orbit around the star due to traveling faster than the escape velocity of the star. They would then roam the galaxy until they were captured by another star. The velocity and mass necessary for this to happen can be calculated, but I wrote a program using simple equations to demonstrate how two planets may suddenly enter a stable orbit if they're traveling at a slow enough velocity relative to each other. They may also be broken apart when another planet passes close by.


This screen saver creates a number of balls (planetoids). Each ball has a mass and velocity that is tracked in two dimensions. As a timer ticks, each ball is moved according to its velocity, which is adjusted by calculating a gravimetric pull (attractive force) exerted by each ball on every other ball.

Two adjustments are made to keep the calculations reasonable and fun to watch. First, gravimetric force is not calculated if two balls are too close to each other. This prevents a divide by zero error, and it also prevents the balls from flying apart at excessively high speeds. Second, when a ball hits the edge of the screen, it will bounce back, but with a velocity adjusted by a user adjustable setting (By default, a 99% reduction in velocity on rebound).

The position of each ball is tracked over time, and this information is used to generate a trail. The program will also adjust for multiple monitors, with separate tracks on each monitor.

Two balls in a large orbit. Notice the trail fades to black.

Chaos ensues as the balls shoot past each other.


Install instructions are available for the following operation systems:

Windows XP


Click here to learn more about Settings


Last edited Sep 20, 2009 at 5:21 AM by erakickas, version 8