Afterglowscreensavers

Stars in a Gravitational Field Screensaver

Stars in a Gravitational Field is a free, in-browser physics screensaver where hundreds of points are pulled around invisible gravity wells, tracing orbits, slingshots and glowing spirals. Each star feels a real inverse-square pull toward the wells, so the motion is genuine n-body-style physics, not a canned animation. It runs full-screen with no download, and ESC exits.

Live preview

Stars in a Gravitational Field screensaver — Caught in the pull.

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

How the Stars in a Gravitational Field screensaver works

The screensaver places one or more gravity wells on screen and fills the field with stars. On every frame each star sums the gravitational pull from every well using a real inverse-square law — the force grows as 1 divided by the square of the distance — then that acceleration updates the star's velocity, and the velocity updates its position. Closer stars get yanked hard; distant ones drift, exactly as gravity works.

Stars aren't dropped in at rest. Each one is spawned with a sideways, tangential velocity tuned to roughly orbital speed for its distance from the centre, so instead of falling straight in they sweep into curving orbits, ellipses and slingshot flybys. The Gravity strength control scales the pull, turning gentle wide orbits into tight, whipping spirals.

The wells themselves don't sit still. When you have more than one, they slowly circle the centre of the screen, so the gravitational landscape is constantly shifting and stars are handed off between wells in chaotic, never-repeating patterns. The Gravity wells control sets how many there are, from a single central attractor up to four.

With Motion trails on, the screen isn't fully cleared each frame — instead it's washed with a faint layer of the background color, so each star smears its recent path into a glowing streak that reveals the orbit lines. Stars that get flung far off-screen are recycled back in from the edge, so the field stays full forever.

Inverse-square gravity and why orbits are hard to predict

Isaac Newton’s law of universal gravitation says that the attraction between two masses falls off with the square of the distance between them: double the distance and the pull drops to a quarter. Electric force between charges follows the same inverse-square form, and in both cases the force near a source becomes very strong at close range.

One body orbiting another is a solved problem: the path is a conic section, an ellipse for a bound orbit, or a parabola or hyperbola for a body passing through. Add a third body and the equations are not integrable, so there is no general formula for the positions over time. Karl Sundman did find a power-series solution in 1912, but it converges so slowly that it is of little practical use, and for most starting conditions the motion is chaotic, so numerical integration is the practical method.

A numerical simulation advances in small time steps, and a star passing very close to a well feels an enormous acceleration that a coarse step can handle badly. The display is therefore best seen as a physically inspired sketch rather than a precise prediction.

A worked example

The defaults — 280 stars, Gravity strength 5, 2 gravity wells, Motion trails on, gold stars (#ffd27f) on near-black — give you two glowing wells orbiting the centre while streams of gold spiral between them. For a single hypnotic vortex, set Gravity wells to 1 so one well sits dead centre; for chaotic, churning slingshots, raise it to 4 and push Gravity strength toward 12.

Settings & tips

Frequently asked questions

Is the Gravity Stars screensaver free?
Yes. It runs free in your browser with no download or sign-up. Open the page, let it fill the screen, and press ESC to exit.
Is this real gravity physics?
Yes. Each star is pulled toward the gravity wells using a real inverse-square law, so the force grows as the distance shrinks. The orbits and slingshots emerge from that simulation.
What are the gravity wells?
They are the glowing points of attraction the stars orbit around. You can have between one and four, and when there are several they slowly circle the centre of the screen.
Why do the stars swirl instead of falling straight in?
Each star starts with a sideways velocity close to orbital speed for its distance, so gravity bends it into a curving orbit rather than a straight drop, producing spirals and flybys.
How do I get smoother orbit trails?
Turn on Motion trails. The screen is then only partly cleared each frame, so each star smears its recent path into a glowing streak that traces its orbit.
What is the three-body problem?
It is the problem of predicting the motion of three masses that attract one another. The equations are not integrable, so there is no general closed-form solution, and for most starting conditions the motion is chaotic. Numerical integration is the practical approach.
Why do some stars get flung out at speed?
A close pass to a moving attractor can change a star’s speed and direction sharply. Spacecraft use the same gravity-assist effect: a probe gains speed relative to the Sun by taking a tiny amount of energy from a planet’s orbital motion.

← All Generative screensavers