Skip to content
bobjenPublic

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

orbit

JavaScript n-body gravitational orbit simulator, rendered on an HTML5 canvas.

Original implementation by Bob Jenkins (2019, public domain).

Documentation and live demos: https://burtleburtle.net/bob/js/orbit.html

How it works

Newton's law gives accelerations from positions and masses. Positions are advanced using an explicit symmetric multistep method (1–15 prior accelerations, default 8), which is time-reversible and far more accurate than simple Verlet or Runge-Kutta. Several integration steps are taken per displayed frame.

Massless bodies (mass 0) are skipped when computing forces on other bodies, so a system with one massive sun and 1000 massless satellites runs in O(n) time rather than O(n²).

Controls

  • Click without dragging — pause / resume
  • Drag near the center — rotate the view (left/up)
  • Drag near the edge — zoom and roll

Usage

<script src="orbit.js"></script>
<canvas id="sim"></canvas>
<script>
orbit({
    name: "sim",
    increment: 0.0015,
    work: 10,
    points: 8,
    background: "#000000",
    trail: true,
    eye: new Eye(5.0, new Point(0.0, 0.0, 0.0), 500.0),
    moons: [
        new Moon("sun",   new Point(0,0,0), new Point(0,0,0), 1000.0, "#ffff00", 0.05),
        new Moon("earth", new Point(5,0,0), new Point(0,0,-14), 1.0,  "#00aaff", 0.02),
    ]
});
</script>

Parameters

Parameter Default Description