Cosmos: a GPU N-body gravity simulation in your browser

Cosmos creates thousands of random planets and lets real Newtonian gravity do the rest. Every planet attracts every other planet; planets that touch merge, conserving mass and momentum. A dense core collapses into a star within seconds, most of the planets collide during the first minutes, and the survivors settle into a flat, stable solar system on nearly circular orbits.

All physics runs on the GPU: the N² force pass, collision detection, merging and integration are WebGL2 fragment shaders working on float textures. It is a single HTML file with no dependencies.

Source code and documentation on GitHub

COSMOS

Planets
Collisions
Stars
Largest mass
Time
Phase
GitHub
Drag rotate · Wheel zoom · Space pause · N new universe · T trails · F follow the largest star · O auto-rotate · +/− speed · P screenshot · H hide panels