Visualizations
402 / 500

402 · Astronomy

Planet Forge

A dusty disk grows rocky worlds, ice giants and gas giants by N-body accretion.

A young star is circled by thousands of planetesimals and a few dozen embryos. Embryos pull on everything, planetesimals feel the star and the embryos and pull back on the embryos, so dynamical friction and scattering come out of the same sums; planetesimals take block time steps by orbital period so the slow outer disk costs as little as the fast inner one. Collisions merge perfectly within a few Hill radii, conserving mass and momentum. While the gas lasts it drags solids inward until they pile up in pressure traps at the inner edge and just past the frost line, damps eccentricities, drives type I migration, and lets icy cores above about three Earth masses run away into gas giants that carve gaps in the glowing gas. Then the gas clears, embryos stir each other into giant impacts, and the strip at the bottom compares the final system with earlier runs.

Try it. Click for a new system from a new seed. Drag to tilt and turn the disk. F or Space fast-forwards, arrow keys tilt and rotate. When a system is finished it is added to the comparison strip, and an idle view forges the next one.

  • Hybrid N-body with block time steps
  • Perfect-merger accretion
  • Gas drag and migration traps
  • Osculating Kepler orbits

View the source · one module, plus a small shared runtime for sizing, the animation loop and input

Build your own

Paste this into Claude Code, Codex or any coding agent to get a simple version running, then take it wherever you like.

Build a protoplanetary disk that grows its own planets, using JavaScript and the HTML canvas element. Put everything in a single index.html file with no libraries or build step, so I can open it directly in a browser.

Start simple:
- Use units where the star's GM is 1 and draw it at the center of a canvas that fills the window. Place about 1,500 small planetesimals on nearly circular orbits between radius 0.3 and 2.5, each with speed sqrt(1 / r) and a little random eccentricity.
- Add about 20 heavier embryos spread through the same range. Only embryos have gravity of their own: planetesimals feel the star and the embryos, embryos feel the star, each other and the planetesimals.
- Step everything with a symplectic (leapfrog) integrator and a time step small enough for the innermost orbit.
- When a planetesimal comes within a couple of Hill radii, r * (m / 3)^(1/3), of an embryo, merge it in, conserving mass and momentum. Do the same when two embryos collide.
- Draw planetesimals as dots and embryos as circles that grow with their mass.

Once that works, make it beautiful:
- Add a frost line at about radius 1.3: solids beyond it carry ice, are more plentiful and are drawn pale blue, while rocky ones inside are rust colored.
- Draw a glowing gas disk behind everything that slowly fades away, and while it lasts let it damp eccentricities and let big icy cores swell into banded gas giants.
- Draw each planet's orbit as a Kepler ellipse computed from its position and velocity, and click to reseed a new system.

Explain the key ideas in short code comments. When you're done, tell me how to open it and suggest three directions I could take it next, such as gas drag that traps solids at the frost line, migration of embryos through the gas, or a strip that compares the final systems from several runs.
PreviousDrumheadA floor tom whose sound is sampled live from the 2D wave equation that draws its head. NextCollatz CoralThousands of Collatz sequences grow backward from 1 into a swaying coral.

Related visualizations

  • Gas Giant WeatherFluids Real 2D fluid dynamics paints turbulent belts, festoons and oval storms on a gas giant.
  • PlanetAstronomy A procedurally generated world with oceans, clouds and a glowing atmosphere.
  • Stellar VampireAstronomy A star overflows its Roche lobe and feeds a white dwarf's disk until it ignites a nova.
  • Orbital ResonanceAstronomy A seven-planet resonant chain that chimes on every transit and weaves its own spirograph.
  • Dark Matter CurveAstronomy Switch off the dark halo and watch a spiral galaxy fly apart.
  • Galaxy CollisionAstronomy Two spiral galaxies collide and fling out long tidal tails.
  • Kirkwood GapsAstronomy Thousands of asteroids and Jupiter's resonances carving gaps into a featureless belt.
  • RingmakerAstronomy Backlit planetary rings with shepherd moons, wavy gap edges, propellers and waves.
  • CometAstronomy A comet rounds the Sun and grows a straight blue ion tail and a curved dust tail.

Use ← and → to move between demos. While the canvas has focus, keys go to the demo instead.

← More from Emergent Mind Labs