Skip to content

Tiny openGL project that displays the Sun, Earth and Moon rotating and orbiting in a realistic scale

License

Notifications You must be signed in to change notification settings

ehrlz/solar-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solar System

This project utilizes Python and the OpenGL library to showcase a simple animation of the solar system, demonstrating the rotation of the Earth around the Sun along with the Moon's orbit around the Earth. Textures are incorporated to represent the Earth, the Sun, and the Moon.

solar-system

PythonOpenGL

Requirements

  • Python3
  • OpenGL
  • PIL (Python Imaging Library)

You can install the dependencies using the following command:

pip install PyOpenGL Pillow

How to run

  1. Download the source code or clone the repository:
git clone [email protected]:ehrlz/solar-system.git
cd solar-system
  1. Run the script in your terminal.
python3 solar_system.py

Functionality

  • LoadTextures(image) handles loading the necessary textures for the Earth, the Sun, and the Moon. Make sure to have the corresponding images in the "textures" folder within the project directory.

  • The earth(), sun(), and moon() functions create the respective lists for each celestial body, configuring the appearance and texture of the spheres.

  • The init() function initializes the OpenGL window, sets the background color, and enables depth testing.

  • The dibujo() function defines the position and rotations of the Earth, the Sun, and the Moon. It also uses the previously created lists to render the celestial bodies.

  • The idle() function manages the updates of rotation angles to simulate movement over time.

  • The setangle(alpha) function ensures that angles stay within the appropriate range.

  • The reshape(newwidth, newheight) function adjusts the projection matrix when the window size changes.

The animation represents in real scale (not the Sun) the rotation of the Earth around the Sun, the Moon's orbit around the Earth, and the rotation of the Sun. Angles and speeds are configured to make the animation perceptible and enjoyable. Experiment with parameters according to your preferences.

Configurable Parameters

You can experiment with the following parameters in the script to customize the animation according to your preferences:

  • Rotation Speed (k): Multiplication factor affecting the rotation speeds of the Earth, the Moon's orbit, and the Sun's rotation. Adjust the value for faster or slower rotations.
  • Texture Paths: Ensure the images for Earth, Sun, and Moon are placed in the "textures" folder. You can replace the file paths in LoadTextures(image) with your own texture paths.
  • Window Size: Modify xw and yw variables to change the initial size of the OpenGL window.
  • Initial Camera Position: Adjust the values in glTranslatef(0, 0, -100) in dibujo() to change the initial camera position.
  • Aspect Ratio and Perspective: Tune the angle and aspect variables in init() to modify the field of view and aspect ratio.
  • Scaling Factors: Experiment with the scaling factors glScalef() calls to change the size of the Earth, Moon, and Sun in the animation.

About

Tiny openGL project that displays the Sun, Earth and Moon rotating and orbiting in a realistic scale

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages