gizmobench
BrowseDaily

Gravity Simulator

Explore a 2D sandbox with 2 to 50 point bodies in dimensionless units. Edit masses, positions and velocities, then run, pause or step. Compare attraction (G = 1), straight motion with gravity off (G = 0), and explicitly fictional pair repulsion (G = -1), watch the center of mass, and save runs as CSV or the starting setup as a project file.

motionfigure-eight, paused
Motion drawing, G = 1. Center of mass at x 0.0000, y 0.0000. 3 bodies at t 0. body 1 at x 0.9700, y -0.2431; body 2 at x -0.9700, y 0.2431; body 3 at x 0.0000, y 0.0000.
Preparing the drawing.
speed, steps a frame

white diamond marked COM is the center of mass numbers mark bodies, lines are trails drag a body to edit it at t 0 G = 1

bodies at t 03 of up to 50, shown to 4 places
the setup you edit
bodymassxyvxvy
110.9700-0.24310.46620.4324
21-0.97000.24310.46620.4324
310.00000.0000-0.9324-0.8647
gravity

Off gives constant velocity. Fictional repulsion reverses pair forces and potential; it does not represent achievable anti-gravity. Changing the mode restarts at t 0; each example loads its stated mode.

t 0, 0 steps of dt 0.01, leapfrog G = 1, softening 0, energy E0 -1.28714 energy drift 0 max so far momentum |p| 0 now, change 0 max center of mass now (x, y) = (0.0000, 0.0000), shown to 4 places center of mass off its straight line by 0 max

Bodies
3, figure-eight
Time
t 0, dt 0.01
Energy drift
0 max
Net momentum
0

  • Equal-mass pair, symmetricm 1 at (-0.5, 0) and (0.5, 0), v (0, -0.7071) and (0, 0.7071), 444 steps of 0.01
    the center of mass stays at (0, 0): largest offset 0 over 444 steps
  • Zero net momentum at startfigure-eight preset, 633 steps of 0.01
    |p| stays under the 1e-10 tolerance on all 633 steps
  • Circular pair, halved time step444 steps of 0.01, then 888 of 0.005 (loads the 0.005 run)
    max energy error falls from 1.0e-8 to 6.2e-10, 16 times smaller

Units are dimensionless. With gravity on, G = 1: without softening, a mass of 1 pulls a body 1 unit away with an acceleration of 1. With gravity off, G = 0: pair forces and potential energy are zero, and bodies move straight at constant velocity. With fictional repulsion, G = -1: pair forces push apart and pair potential is positive. This is a mathematical toy, not achievable anti-gravity. The COM diamond and coordinates show the mass-weighted center of the current point bodies. Energy drift uses |E - E0| / |E0|, or absolute change when |E0| is at most 1e-12. Worked cases load with gravity on.

Common questions

How does a gravity simulator work?
With gravity on, every body pulls every other with a force of G times the two masses over the distance squared, with G = 1 in dimensionless units; softening modifies this at close distances. The page adds up the pulls for every pair, then moves the bodies forward with kick-drift-kick leapfrog: half a step of velocity change, a full step of motion, then the other half with the new pulls. The two pulls in each pair are equal and opposite, so net momentum is conserved to rounding. With gravity off, G = 0, each body keeps its velocity and follows a straight line.
What is energy drift, and why does it matter?
The total energy of an isolated system, kinetic plus potential, should not change, but finite time steps make it wander. The page records the starting energy E0 and shows the largest |E - E0| / |E0| over every step so far, or the plain change when E0 is within 1e-12 of 0. For the circular pair, 444 steps of 0.01 reach a largest error of 1.0e-8, and 888 steps of 0.005 over the same time reach 6.2e-10, 16 times smaller. Above 1% the page notes that a close pass between two bodies is the usual cause.
What does softening do?
With attraction or fictional repulsion, softening replaces the distance squared with the distance squared plus the softening length squared in the force and potential energy. Close passes become calmer, but the orbits differ from the unsoftened result. With softening 0, two bodies starting at the same point are refused, and a run in which two bodies meet at one point stops at the last finite step with a message. With gravity off there is no pair force or potential, so bodies may cross or overlap and softening has no effect.
Why do the bodies fly apart in the Pythagorean 3-4-5 example?
Masses of 3, 4 and 5 start at rest at the corners of a 3-4-5 right triangle and make very close passes. A fixed step of 0.001 cannot follow those passes accurately: by t 20 the page shows an energy drift of 1.2e+2, an error about 120 times the starting energy, so the paths after the first close passes are not a faithful solution. The example is there to show what the drift readout is for.
Can this predict real orbits or plan a spacecraft trajectory?
No. Units are dimensionless with G = 1, 0 or fictional -1, bodies are points moving in a plane, and the step size is fixed. The simulator is for exploring how gravity and numerical integration behave, not for astronomy, navigation or mission planning.
How many bodies can it simulate, and what values are allowed?
From 2 to 50. Add body places a body of mass 0.001 just outside the others. With gravity on, it uses an estimated circular-orbit speed sqrt(M / R) for their total mass M at distance R from their center of mass, plus the center's velocity. With gravity off or fictional repulsion, it moves with the center's velocity. Remove deletes the selected body. Mass must be above 0 and at most 1000, positions and velocities lie between -1000 and 1000, the time step between 0.00001 and 1, and softening between 0 and 10.
What do the CSV and project files contain?
The CSV has one row per body per recorded sample, with step, t, body, mass, x, y, vx, vy, energy, energy_drift, momentum_x and momentum_y. Gravity-off runs append gravity_G = 0. Fictional repulsion runs append gravity_G = -1 and force_model identifying fictional pair repulsion. Samples start at t 0; once there are more than 1,000, the page keeps every other one and doubles the interval. The last rows are always the current state. The project file is JSON holding the bodies, time step, softening and G at t 0, which Open project loads back. Older files without G default to gravity on; unsupported G values and files over 1 MB are refused.
Can I use it without a mouse, and does it remember my setup?
Yes to both. Bodies are edited in labelled fields, and with the drawing focused Space plays or pauses, period steps once, plus and minus zoom, the arrow keys pan and F fits the view. The setup, gravity mode, trails, vectors, speed and stop time stay in this browser's storage for your next visit, and the run starts again from t 0. Older saved setups default to gravity on. The page opens running, or paused when your device asks for reduced motion.
Can I run this gravity sandbox online on a phone or Mac?
The simulation runs for free in your browser, needs no account or software installation, and offers labelled fields for editing bodies. On a phone, edit the fields or drag a body while paused at t 0. It models motion in two dimensions; it does not bypass a network that blocks this site.
Can I explore a simplified gravity assist?
You can edit the masses, positions and velocities of point bodies and observe how a close pass changes their motion. A three-body setup can represent a moving massive body, a central body and a small passing body. The energy-drift readout helps show when the chosen time step stops following a close pass accurately. This is a dimensionless teaching model, not a real spacecraft trajectory calculation.
How do I compare gravity with zero-gravity motion?
Pause the run, edit the starting positions and velocities, then choose Off (G = 0) and press Play or Step. Each point body keeps its velocity, pair potential energy is zero, and total energy is kinetic energy. Choose On (G = 1) to restart the same starting bodies with attraction. Changing the mode restarts at t 0; loading an example restores its stated mode, and worked cases restore gravity on. This is a zero-force comparison in two dimensions, not a physical weightlessness experience or a uniform Earth, Moon or artificial-gravity model.
Where is the center of gravity in this point-body model?
The white diamond marked COM and the live (x, y) readout identify the current center of mass, shown to four decimal places. Each coordinate is the sum of mass times position divided by total mass. For masses 1 and 3 at (-2, 3) and (2, -1), it starts at (1, 0). This dimensionless point-mass output is a center of mass; interpreting it as a center of gravity assumes a uniform external field. The simulator applies pairwise attraction, zero force or fictional repulsion and does not model that external field.
What does the zero-gravity simulator cost?
This browser simulation is free to use and needs no account or installation. Choose Off (G = 0) to run editable point bodies at constant velocity. This price refers to this online simulation; it does not quote physical weightlessness flights, venues or equipment.
Can I simulate a simplified Solar System?
Choose Approximate Solar System and press Load, then Play or Step. Bodies 1 to 9 are Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus and Neptune. Sun mass is 1; the eight rounded planet masses are 1.66e-7, 2.45e-6, 3e-6, 3.23e-7, 9.54e-4, 2.86e-4, 4.37e-5 and 5.15e-5. Their starting distances from the Sun are 0.387, 0.723, 1, 1.524, 5.203, 9.537, 19.191 and 30.069, relative to Earth at 1. All start in one plane at arbitrary phases with tangential speed sqrt(1 / radius); positions and velocities are shifted so the center of mass starts at rest at the origin. The time step is 0.001 with G = 1 and no softening. Mutual pulls then change the motion. Zoom in for inner planets. These are approximate circular starts, not dated positions or a real-orbit prediction.
Can I simulate low or reduced gravity without turning it off?
Choose Weak attraction and press Load, then Play or Step. A body of mass 0.1 and a small orbiter of mass 0.000001 start one distance unit apart with G = 1 and no softening. The small body starts with acceleration 0.1, one tenth of the Earth comparison at the same distance, so the pull is weaker but nonzero. Both bodies start in a circular orbit about their stationary center of mass. The time step is 0.001. This is reduced point-body attraction, not a walking or surface-gravity model.
Can I compare Earth, lunar and Mars gravity?
Choose Approximate Earth comparison, Approximate Moon comparison or Approximate Mars comparison and press Load. Body 1 represents the named central body; body 2 is a small orbiter of mass 0.000001. Earth mass is 1, with rounded Moon and Mars masses of 0.0123 and 0.107 in that same mass unit. Each pair starts one arbitrary distance unit apart, so the small body starts with acceleration 1, 0.0123 or 0.107 respectively. Relative tangential speed is sqrt(central mass + 0.000001), and both positions and velocities are shifted to a stationary center of mass. All three use G = 1, time step 0.001 and no softening. The same distance is used for comparison, not each planet's radius: these point bodies model mutual attraction and circular starts, not surface gravity, walking, real dates or predicted real orbits. The Moon comparison costs nothing to use in this browser; this is the price of the simulation, without equipment or facility pricing.
Can I simulate anti-gravity?
Choose Fictional repulsion and press Load, then Play or Step, or choose Fictional repulsion (G = -1) for your own starting bodies. This mathematical toy reverses both the pair force and pair potential, so two stationary unit masses one unit apart start with outward acceleration 1 and total energy 1. The example uses time step 0.001 and no softening. You can edit bodies, reset, remember the setup, and export projects or CSV with the fictional mode identified. It does not represent achievable anti-gravity or a physical experience.

A dimensionless teaching simulation with attraction (G = 1), zero force (G = 0) or fictional pair repulsion (G = -1). Finite time steps and softening change the result, so energy and momentum drift are shown. Repulsion reverses the pair force and potential together; it does not represent achievable anti-gravity. This model does not predict real orbits or plan navigation.