This project is developed as final project for Harvard University's CS50x Introduction to Computer Science Course, in August 2023.
It is a simple solar system simulation using Python's Pygame module, using Newton's second law of motion and Newton's law of universal gravitation with actual properties of the celestial bodies (only Sun and the planets).
Main idea of the project is inspired from Tech With Tim's Planet Simulation In Python - Tutorial video, which I have watched while I was trying to learn Pygame module before I enrolled in CS50x. I have added various features and applied it to the full scale of Solar System, using the same calculations, which are Newton's universal laws, as stated above.
You may find the video demo of the project here.
- Distances are to scale, sizes are not to scale.
- Calculations are done regarding Newton's laws with actual properties of the celestial bodies (Retrieved from NASA's fact sheets)
- Dynamically shown celestial body information (by selecting desired celestial body with keyboard or hovering mouse at desired instance)
- Dynamically colored indicators to show user that particular celestial body is selected
- Dynamically updating orbital velocities and orbits (not to forget that orbital velocities and orbits are just fine approximations as moons and other celestial bodies are excluded in this simulation)
- Ambient background music
- Ability to pause/unpause the simulation
- Ability to toggle on/off celestial body information (refer above)
- Ability to mute/unmute the background music
- Ability to quit the simulation any time by pressing Q as screen borders may be invisible depending user's display resolution
- As Uranus' and Neptune's orbits may sometimes be out of the screen, an arrow indicating current position of the related planet is drawn for user to be able to keep track of the planet
- Make sure that all the files are in the same folder, e.g.
project
- Change your directory to the folder you keep the files, e.g.
cd path\project
- Install dependencies from the
requirements.txt
by executingpip install -r requirements.txt
at your IDE's terminal (or command prompt). This will successfully install Pygame. - Start the program at your IDE's terminal (or command prompt) by executing
python main.py
You may find the shortcuts useful:
Key | Function |
---|---|
P | Pause / Unpause simulation |
M | Mute / Unmute background music |
I | Toggle information off (when on) |
Q | Quit simulation |
0-8 | Display celestial body information (Sun to Neptune) |
MOUSE 1 | Toggle information off (when on) |
All assets used in this project are copyright-free.
- Background music is retrieved from Pixabay. Credit to: SamuelFrancisJohnson. You may find it here.
- Celestial bodies' images that appear on bottom-left corner are retrieved from NASA.
- Celestial bodies' astronomical symbol images are retrieved from Wikipedia under Creative Commons License. Find particular images: Sun, Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune. Converted to JPG and edited on MS Paint for black background - white foreground change.
This project is developed solely by myself as a final project for Harvard University's CS50x Introduction to Computer Science Course. I have no commercial or monetary purposes. This is developed only for educational purposes.
Special thanks to Harvard University, Prof. David J. Malan, and the staff!
Many thanks for checking this project and trying the simulation. Your interest is very much appreciated.
Please do not hesitate to contact me if you have questions regarding the project or any other related subject. Mail me here.