A fun project with visually engaging planetary motion simulation built using Python and Pygame, based on Newtonian gravity.
It models the orbits of planets around the Sun using real-world astronomical data and physical equations.
- Realistic gravitational motion using Newton’s law of universal gravitation
- Toggle between outer and inner solar system views (
Zkey to zoom) - Trail tracking for each planet to visualize orbital paths
- Time-step based simulation (1 day per frame)
- Scalable simulation with two distinct zoom levels:
- Outer Solar System (
SCALE) - Inner Solar System (
ZOOM_SCALE)
- Outer Solar System (
- Smooth 60 FPS rendering with Pygame
| Key | Action |
|---|---|
Z |
Toggle between zoomed-in and zoomed-out view |
ESC / Close Window |
Exit simulation |
git clone https://github.com/<your-username>/planet-simulation.git
cd planet-simulationpip install pygamepython main.pywhere
- (G = 6.67430 \times 10^{-11}) (gravitational constant)
- (m_1, m_2) = masses of two bodies
- (r) = distance between them
Then velocity and position are updated using:
v = v + a dt
x = x + v dt
Each frame represents 1 day (DT = 86400 seconds).
Outer Solar System View: Uses SCALE = 6e-11 (meters → pixels). Shows all planets up to Pluto.
Inner Solar System View: Uses ZOOM_SCALE = 1e-9 for a closer look at Mercury–Earth region.
Press Z anytime to toggle views.
Trails are cleared upon zoom toggle for clarity.
planet-simulation/
│
├── planet-orbits.py # Core simulation file
├── README.md # Project documentation
└── requirements.txt # Dependencies (optional)