This project demonstrates a couple examples of 3D with rainbow-colored borders using Pygame Community Edition and OpenGL.
Current examples:
- cube.py - a rotating cube
- torus.py - a rotating torus
- pyramid.py - a rotating pyramid
- dragon.py - a custom shape model loaded from an stl file
This is a personal project to test the functionality of Pygame and PyOpenGL.
- 3D rotating shape rendered with OpenGL
- Rainbow-colored rectangles at the top and bottom of the window
- Smooth color transitions in the rainbow borders
- Python 3.x
- Pygame Community Edition
- PyOpenGL
-
Clone this repository or download the source code.
-
Install the required dependencies:
pip install -r requirements.txt
Run the scripts using Python:
python cube.py
or
python torus.py
or
python pyramid.py
or
python dragon.py
- Close the window to exit the program
The program uses Pygame Community Edition to create a window and handle events, and OpenGL for 3D rendering. The main components are:
- A 3D shape that rotates continuously
- Two rainbow-colored rectangles at the top and bottom of the window
- Color transitions that create a moving rainbow effect
The shape is defined by its vertices and edges, and drawn using OpenGL lines. The rainbow effect is achieved by calculating HSV colors and converting them to RGB.
You can modify various aspects of any of the programs:
- Adjust the window size by changing the
display
tuple in themain()
function - Modify the shapes's rotation speed by changing the values in the
glRotatef()
call - Adjust the rainbow effect speed by modifying the hue increment value
the free STL model asset file (cutedragon2.stl) is from https://cults3d.com/en/3d-model/art/cute-dragon-jkcreate