The science

Real gravity, browser-sized galaxy

Galacto is a self-gravitating N-body galaxy sandbox: tens of thousands of stars, each pulling on every other through the same Newtonian gravity used in real galaxy simulations, scaled down for a browser. No scripted arms, no canned animation — the spirals, bars, tidal bridges and merger remnants are consequences of the dynamics. This page is the split between what is really being simulated and what is deliberately approximate.

01Gravity, all of it

Every body carries a mass and feels the pull of every other body — the full all-pairs sum, with no tree code or particle-mesh approximation to the force. The acceleration of body i is Newtonian gravity summed over all j:

ai = Gj mj (rjri)(|rjri|² + ε²)3/2 with a Plummer softening length ε in the denominator

That ε² is the one liberty taken with Newton. A pure 1/r² force diverges when two bodies pass arbitrarily close, and with a finite timestep that produces spurious slingshots that wreck energy conservation. Softening replaces each point mass with a small Plummer sphere, capping the force at short range — the standard, physically-motivated fix in collisionless N-body work. It also stands in for the fact that each simulated body represents millions of real stars, not one.

In the sandbox

16,384 bodies by default, adjustable up to ~164,000 with the Bodies slider. Per-body mass scales as 1/N, so adding bodies refines the same galaxy rather than piling on mass. The cost is real: all-pairs gravity is O(N²), which is exactly why a browser sim lives in the thousands, not the billions.

02Moving the stars: the leapfrog

Integrating those accelerations forward in time is where naïve methods quietly fail. Galacto uses the leapfrog (drift–kick–drift) scheme, advancing each body by a fixed step dt in three moves:

xx + v·dt/2   →   vv + a·dt   →   xx + v·dt/2 drift a half-step, kick with gravity sampled at the midpoint, drift the second half

Leapfrog is symplectic: it preserves the geometric structure of Hamiltonian (energy-conserving) flow, so the total energy oscillates within a bound instead of drifting away. A simple Euler step, by contrast, leaks energy every orbit and would let the cold disk puff up or spiral in within a few rotations. That stability is what lets a thin disk survive long enough to grow arms.

The step is fixed at dt = 1/60 in simulation time and decoupled from your screen's refresh rate by an accumulator, so a slow display does not make the integrator take bigger, less accurate steps. The seeded initial conditions are repeatable; the long-run path is not promised bit-for-bit across different GPUs.

03Putting numbers on it

The solver runs in arbitrary units with G = 1. Two anchors turn those into recognisable galaxy scales for the on-screen readouts:

Because G = 1, the time scale then follows from length ÷ velocity: one time unit ≈ 33 million years. With those, the disk's scale length (35 units) reads ≈ 3.5 kpc and its mass works out to ≈ 7×1010 solar masses — all squarely galaxy-plausible. The Speed readout shows millions of years of simulated time per real second, and the clock on the rotation-curve overlay shows elapsed Myr.

Worth knowing

These factors are for display only — the solver never sees them. They re-label the visuals in physical units without touching the dynamics, so the equations hold in real units too.

04Dark matter and the flat rotation curve

Spin a galaxy's visible mass and Newton predicts the orbital speed should fall with radius once you're outside most of the light — the way planets slow down further from the Sun. Real galaxies don't: their rotation curves stay flat far beyond the visible disk. The standard explanation is an enormous, invisible dark-matter halo whose mass keeps growing with radius. Galacto adds that halo as a static background force, in two selectable shapes:

Logarithmic:  vc² = v0² r²r² + rc² flat at large r; an unbounded potential, so the system stays bound and debris always returns
NFW (cold dark matter):  vc² ∝ ln(1+x) − x/(1+x)xx = r/rs rises to a peak near r ≈ 2.16 rs then declines; a finite potential, so fast debris can escape

The Curve overlay plots the circular speed against radius and splits it into its three contributions — bulge, disk and halo — which add in quadrature:

vc²(r) = vbulge² + vdisk² + vhalo²

The flat outer part is held up almost entirely by the halo — the classic observational clue behind dark matter, made visible as a live decomposition. Drag the Strength slider (in km/s) or the Size slider (the halo's scale radius, in kpc) and watch the curve respond: a concentrated halo rises steeply in the centre, a diffuse one gently.

05Why spiral arms form: the Toomre Q

A cold, rotating, self-gravitating disk is poised on a knife-edge. Too cold and its own gravity wins, collapsing it into clumps; too hot and random motions smear out any structure. In between lies the regime where small disturbances get amplified into the grand sweeping arms of a spiral. The control parameter is the Toomre stability parameter:

Q = σR κ3.36 G Σ σR = radial velocity dispersion · κ = epicyclic frequency · Σ = surface density

Here κ is the epicyclic frequency — the rate at which a slightly-disturbed star oscillates radially as it orbits — read straight off the rotation curve via κ² = 2Ω(Ω + dvc/dr). The stability sequence is sharp:

The Toomre Q slider sets the target Q for the next seed. The sim inverts the relation to assign each radius the dispersion it needs — σR(r) = Q · 3.36 G Σ(r) / κ(r) — so the disk is born at your chosen stability and then evolves on its own after Restart or a scenario switch.

Honest about the model

Softening, the disk's finite thickness, and the modest particle count all make this disk more stable than razor-thin Toomre theory predicts. So an empirical correction is applied to make the slider read an effective Q, calibrated so the spiral sweet spot lands near Q ≈ 1.3. The radial shape of the dispersion and the stability sequence are physically right; the absolute number is tuned to this softened, finite-N disk.

06Cold gas, and the blue arms

Stars are collisionless — they pass through one another's neighbourhoods without colliding — so a purely stellar disk slowly heats up and its arms fade. Spiral galaxies keep sharp arms because of their cold gas, which is collisional: it radiates energy away, shocks, and settles into a thin, cold layer that keeps responding sharply to the disk's gravity. That gas is where new, hot, blue stars are born — which is why the arms of real spirals glow blue.

In the spiral and M51 scenarios, Galacto seeds about a quarter of the disk as a gas component by default (set it with the Gas slider). Each step, the gas damps radial and vertical motion while keeping its tangential circulation — a "sticky gas" stand-in for radiative cooling — so it stays cold while the stars heat and blur. It gathers into the arms and is drawn a bright blue, tracing the star-forming ridges over a warmer, redder stellar disk.

Honest about the model

This is a velocity-damping caricature, not hydrodynamics: there is no gas pressure, no genuine shocks, and no actual conversion of gas into stars with feedback. It captures the one effect that matters for the look and the dynamics — a cold, dissipative component that sharpens and sustains the arms.

07Mergers, and why galaxies fall together

When two galaxies pass close, why can they merge into one remnant rather than simply swinging past? One key mechanism is dynamical friction. A massive body ploughing through a sea of lighter ones — here, the dark-matter halo — gathers an over-dense gravitational wake behind it, and that wake pulls back, draining the body's orbital energy. Chandrasekhar's classic result gives the drag:

adf ∝ − G² M ρ lnΛv² f(X) ∝ the body's own mass M, the local halo density ρ, the Coulomb logarithm lnΛ, and a velocity factor f(X)

Because the drag scales with the perturber's mass, it bites hard on the heavy galaxy cores and is negligible for the featherweight disk stars. So colliding galaxies genuinely lose orbital energy and spiral together — one real merger mechanism — rather than sailing past. The Grand-design (M51) scenario layers a second classic effect on top: a companion's tidal field sweeping past a disk draws out a two-armed grand-design pattern and a luminous bridge, just like the real M51.

Honest about the model

The halo is a static background force, so it can't grow its own wake — the friction is added analytically from Chandrasekhar's formula instead, with the Coulomb logarithm fixed at a galaxy-merger-scale lnΛ ≈ 3 and the local density estimated from the halo's enclosed-mass gradient.

08Bulges and the shape of a galaxy

The Bulge slider sets how much of the galaxy's mass sits in a dense central concentration. Turn it down and you get a disk-dominated late-type spiral with a gently rising rotation curve; turn it up and you get a bulge-dominated early-type galaxy whose rotation curve spikes sharply in the centre. That single axis — how centrally concentrated the light is — is essentially the backbone of the Hubble tuning-fork classification, and you can watch it reshape the decomposed rotation curve live.

09What's real, and what's illustrative

Galacto is a compact model, not a claim to simulate every piece of galaxy physics. The deliberate simplifications are:

And what is genuinely dynamic, arising from the gravitating bodies with nothing scripted:

The takeaway

The visible structures are consequences of the simulated gravity, not animation. The approximations are the price of running the model in real time in a browser tab, and they are chosen to preserve the behaviours that matter on screen.

How it's built: Rust + WebGPU →