# Galaxy Collision (GPU N-body, Three.js)

Two spiral galaxies collide, simulated entirely on the GPU. Open `index.html` through any static server
(e.g. `python3 -m http.server`) — no build step. Three.js r160 is loaded from the jsDelivr CDN; everything else is generated in code.

- **Particles:** 262,144 stars on desktop, 147,456 on touch devices (both ≥ 100k). The live count and FPS are shown top-left.
- **How it works:** positions and velocities live in float render targets (`RGBA32F`, falling back to half-float) that are ping-ponged each step by custom GLSL shaders (kick pass, then drift pass). Stars are attracted by the two softened galaxy cores, which orbit each other under their own gravity. Stars are drawn as additive glowing points coloured by speed (slow = ember/orange, fast = blue-white). Tidal tails and a bridge form after the first pericentre pass.
- **Adaptive resolution:** if FPS drops below 40, the render resolution steps down automatically to stay smooth on phones.

## Controls

| Action | Mouse / keyboard | Touch |
|---|---|---|
| Orbit | Left-drag | One-finger drag |
| Zoom | Mouse wheel | Pinch |
| Time speed | **Time speed** slider (0 = pause, up to 4×) | Same slider |
| New collision | **New collision** button (or `R`) | Same button |

"New collision" restarts with a new random seed: random disc tilts (and so a new angle between the discs), pericentre distance, orbital energy and galaxy mass ratio. The tilt values are shown above the control panel.

Optional URL parameters: `?seed=123` (reproducible collision), `?n=384` (texture side; particles = n²), `?speed=2`.
