Skip to content

Ananay8425/planet-orbits-simulation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Planet Orbits Simulation

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.


Features

  • Realistic gravitational motion using Newton’s law of universal gravitation
  • Toggle between outer and inner solar system views (Z key 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)
  • Smooth 60 FPS rendering with Pygame

Controls

Key Action
Z Toggle between zoomed-in and zoomed-out view
ESC / Close Window Exit simulation

Installation & Setup

1. Clone the Repository

git clone https://github.com/<your-username>/planet-simulation.git
cd planet-simulation

2. Install Dependencies

pip install pygame

3. Run the Simulation

python main.py

How It Works

🔹 Gravitational Force

F = G m1 m2 / r^2

where

  • (G = 6.67430 \times 10^{-11}) (gravitational constant)
  • (m_1, m_2) = masses of two bodies
  • (r) = distance between them

🔹 Motion Update

a = F/m

Then velocity and position are updated using:

v = v + a dt
x = x + v dt

Each frame represents 1 day (DT = 86400 seconds).


Zoom System

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.


File Structure

planet-simulation/
│
├── planet-orbits.py            # Core simulation file
├── README.md          # Project documentation
└── requirements.txt   # Dependencies (optional)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages