A physics-based N-body simulation built with Pygame that simulates gravitational interactions between celestial bodies in real-time.
- 🚀 Real-time gravitational physics simulation
- 🎮 Interactive controls (zoom, trajectories, info display)
- ✨ Visual trajectories showing object movement paths
- ⌨️ Intuitive keyboard shortcuts for various display options
- 🌍 Realistic celestial body physics
- Python 3.x
- Pygame
pip install pygamepython main.pyMake sure you have an image.jpg file in the root directory for the background.
| Key | Action |
|---|---|
| Mouse Wheel | Zoom in/out |
| I | Toggle info display |
| Z | Toggle manual zoom mode |
| T | Toggle trajectories |
| Ctrl+C | Quit application |
nbodysimulator/
├── main.py # Main application entry point
├── events.py # Event handling and user input
├── settings.py # Application settings and preferences
├── parameters.py # Simulation parameters
├── objects.py # Celestial body objects
├── coords_math.py # Mathematical calculations
├── paint.py # Rendering and graphics
├── messages.py # UI messages and text
├── event_booleans.py # Event state management
├── image.jpg # Background image
└── README.md # This file
The simulation uses Newton's law of universal gravitation:
F = G * (m1 * m2) / r²
Where:
- F = gravitational force
- G = gravitational constant
- m1, m2 = masses of the two bodies
- r = distance between centers
Feel free to submit issues and pull requests to improve the simulation!
This project is open source - feel free to use and modify as needed.
