PyGravitas banner

PyGravitas

1 devlog
5h 41m 50s

A real-time interactive 3D gravity sandbox built with VPython. Spawn planets, watch orbits form, trigger collisions, and observe the chaos of the three-body problem — all driven by real Newtonian physics.

Repository

Loading README...

yal212yal

Started from a blank repo with nothing and built an real-time 3D gravitational simulation engine from scratch. Implemented a full N-body physics engine using the Velocity Verlet symplectic integrator with softened pairwise force calculation, inelastic collision merging with exact momentum conservation and volume-conserving radius recombination, and a race condition fix where asynchronous VPython mouse callbacks could corrupt the integration loop mid-step by growing the body list between acceleration snapshots. Designed a complete interactive UI with HTML-styled live readouts, color-coded controls, and per-frame energy and center-of-mass tracking. Built three physically motivated presets: an unequal-mass binary star system with a gravitationally stable circumbinary planet derived from reduced-mass orbital mechanics, a Pythagorean 3-body configuration tuned to stellar masses so chaotic ejection unfolds visibly in real time, and a complete solar system using full Keplerian vis-viva orbit initialization - each of the nine planets plus Pluto placed at their correct true anomaly with proper eccentricity, ecliptic inclination applied via rotation matrix, and trail retention calibrated to their orbital periods. Saturn carries a two-band ring system rendered as a torus pair lying in the orbital plane, appearing as a natural ellipse from the elevated camera angle. Pushed the renderer to cinematic quality with smooth curve trails, floating body labels, emissive glow against pure black with suppressed ambient lighting, CoM-tracking camera drift, and a 120fps update loop - 20 gravitating bodies live at startup.

Attachment
0