Free, in your browser

Gravity simulator

A gravity simulator calculates how masses pull on each other and moves them a tiny step at a time, so you can watch orbits form, wobble and break. This one is free and runs in your browser with no download: tap to drop a planet into orbit, drag to throw one, change any body's mass, and try the Sun, Earth and Moon, the figure-eight three-body orbit, a binary star and a gravity slingshot.

Scaled so you can see it: the real Sun is 333,000 times Earth's mass and the Moon sits 389 times closer to Earth than Earth is to the Sun.

Keys (click the sky first): Space play/pause · R reset · A add a body · T trails · C recenter · + − zoom · [ ] pick a body · Delete remove it

How to use it

How does gravity work?

Every mass pulls on every other mass. Isaac Newton's law of universal gravitation, published in 1687, says the pull grows with both masses and falls with the square of the distance between them: twice as far apart, a quarter of the pull; ten times as far, a hundredth. In symbols, F = G m₁ m₂ / r², where G is a tiny constant, which is why you don't feel the pull of the person sitting next to you.

The pull is the same size on both bodies, pointing toward each other, but the lighter one accelerates far more. That is why Earth swings around the Sun while the Sun only wobbles: both actually circle their shared center of mass, which for the Sun and Earth lies deep inside the Sun.

An orbit is a fall that keeps missing. A planet is always falling toward the Sun, but it is also moving sideways so fast that the ground it falls toward curves away beneath it. This simulator does exactly what the law says: many times a second it adds up the pull on each body from every other body, changes each velocity a little, and moves each body a little.

Why are orbits ellipses?

In 1609 Johannes Kepler found from Tycho Brahe's measurements of Mars that planets move on ellipses, with the Sun at one focus, not at the center. Newton later proved that an inverse-square pull allows only a few shapes of path: a circle, an ellipse, a parabola or a hyperbola. Which one you get depends on the speed.

At one exact sideways speed, the square root of GM/r, the fall and the sideways motion balance all the way round and the orbit is a circle; that is the speed a tap gives a new body here. Throw it a little slower and it falls inward, speeds up as it drops, swings round and climbs back: an ellipse. A little faster and it climbs outward first: a wider ellipse. At about 1.41 times circular speed, the square root of two, it never comes back. That is escape speed.

Along an ellipse a planet is fastest when closest and slowest when farthest, sweeping out equal areas in equal times (Kepler's second law). Earth's orbit is almost a circle; Halley's comet's is a long, thin ellipse that takes it from inside Venus's orbit to beyond Neptune's.

What is the three-body problem?

Two bodies alone always follow those neat shapes, and a formula tells you where they will be at any time. Add a third body of similar mass and there is no such formula. In the late 1880s Henri Poincaré showed why: three bodies can be chaotic, so a tiny change in where they start leads to a completely different future. The only way to know is to calculate step by step, which is what a gravity simulator does.

There are orderly exceptions. Leonhard Euler and Joseph-Louis Lagrange found arrangements that keep their shape, including three bodies at the corners of a spinning equilateral triangle. In 1993 Cris Moore found, by computer, three equal masses chasing each other round a single figure-eight, and Alain Chenciner and Richard Montgomery proved it exists in 2000. The Figure-8 preset starts on it.

Most other starts are messy. Typically the three swing past each other, trade energy, and one is flung away while the other two settle into a tighter pair. The stable triples in nature are lopsided ones: a close pair with a third body far away, like Alpha Centauri's two Sun-like stars with Proxima Centauri far out, or the Moon close to Earth with the Sun far off.

What does this simulation simplify?

It is real Newtonian gravity, but a sandbox, and these are its shortcuts. Everything moves in a flat plane, which is close to true for the planets but not for star clusters. There is no relativity, which only matters near black holes and for tiny effects like the slow turning of Mercury's orbit.

Time moves in small fixed steps using a leapfrog integrator, a method that keeps an orbit's energy from drifting away over many turns. When two bodies pass very close, the step is made smaller for that moment, and if a pass is so close that it would take more than 400 steps in one frame, the sandbox slows down instead. The energy drift readout shows the leftover error; on the presets it usually stays below a thousandth of a percent.

Softening adds a tiny length to every distance (0.1 to 0.5 units here, against orbits hundreds of units wide), so the pull can't become infinite if two points nearly coincide. Bodies that touch merge into one, keeping their total mass and momentum; real collisions also shatter, melt and throw out debris. Bodies that fly about a hundred times farther than the view are let go, and there is room for 60 at once.

The presets are scaled so you can see them. The real Sun is about 333,000 times Earth's mass, and the Moon is 389 times closer to Earth than Earth is to the Sun, so at true scale the Moon's orbit would be invisible next to Earth.

Questions

Is this gravity simulator free?
Yes. It runs free in your web browser on phones, tablets and computers, with no download, no account and no ads. It needs only JavaScript and an HTML canvas, not WebGL, so it runs on older devices too.
How do I add a planet?
Tap or click empty space and a body appears there, moving at circular-orbit speed around whatever pulls hardest at that spot. To choose its speed yourself, drag instead: the arrow sets the speed and direction and a dotted line previews the path. Set the mass first with the slider; the Sun in the presets is 1000.
Why did my planet fly away or crash?
Speed decides the orbit. At about 1.41 times the speed of a circular orbit a body escapes for good. Much slower than circular speed, it falls steeply inward, and if it touches the star the two merge.
How accurate is it?
It uses Newton's law of gravity with a leapfrog integrator, a standard method in astronomy for long orbit calculations. The energy drift readout shows the error as you play; on the presets it usually stays below a thousandth of a percent. It simplifies things: a flat plane, no relativity, a small softening length, and touching bodies merge.
Is this an n-body simulator?
Yes, a small one. An n-body simulation computes the pull between every pair of bodies, which is exactly what this sandbox does for up to 60 bodies, in two dimensions. Astronomers run the same kind of calculation with millions or billions of particles for star clusters and galaxies. For the eight real planets, from where they are today, try the solar system simulator on this site.
Can three bodies have a stable orbit?
Yes, in special cases. The Figure-8 preset is one: three equal masses on a single figure-eight, found in 1993. Lopsided triples are stable too, such as a moon close to a planet that orbits a far-off star. For a moon to stay, it has to orbit well inside the planet's Hill sphere, where the planet's pull beats the star's; for Earth that region reaches about 1.5 million kilometers, roughly four times the Moon's distance.
How does a gravity slingshot work?
A probe that flies close behind a moving planet is pulled along by it. Seen from the planet, the probe leaves as fast as it arrived, only in a new direction; seen from the Sun, it has picked up some of the planet's orbital speed, and the planet slows by an immeasurably small amount. Voyager 2 used Jupiter, Saturn and Uranus this way to reach Neptune in 1989. Try the Slingshot preset.
Is there an app version?
Yes. The Everdust app is free on the App Store for Apple Vision Pro, with a galaxy collision of up to about a million stars you can stir with your hands and the games Black Hole Golf and Galaxy Billiards, and free on the App Store for iPhone and iPad and on Google Play for Android phones and tablets, with games such as Orbit Architect and Black Hole Golf and galaxy collisions of up to about a million stars.

More gravity in the Everdust app

This sandbox is flat and small on purpose, so it runs on any phone. The Everdust app puts gravity in your hands at full scale:

This is one world, in your browser

The full version is in the Everdust app.

The app has many more live worlds at full detail, games built on the same physics and narrated stories you step inside. It’s free to download, with no ads, on the App Store for iPhone, iPad, Apple Vision Pro and Apple TV, on Google Play for Android phones and tablets, on the Meta Horizon Store for Meta Quest and from everdust.ai for Mac.