GL is a simple geometric library for Python that can be used to create simple programs with geometric figures, to create animations or simple games like Ping pong. It uses SDL2 as its backend to create window, draw and handle events. It aims to provide simple API that can help people learn basics of creating simple games.
python
gcc
sh- Clone this repository:
git clone https://github.com/zerfithel/gl
cd gl- Build the module:
source build.shor if you are using Windows:
.\build.bat
- Write your .py code and run it while in virtualenv:
. ./venv/bin/activate # if not in venv already
python <code.py>If you want to learn GL please see zerfithel.github.io. You can also take a look at example projects in examples directory. Here is a simple animation made with GL in Python:
import gl
total_time = 0 # How long animation was ran
# Initialize GL and Window
gl.init()
width = gl.get_monitorwidth()
height = gl.get_monitorheight()
gl.initwindow("Sample animation", width, height, ["resizable"])
# Initialize background
gl.background(10, 10, 10, 255)
gl.clear()
# Set FPS
gl.setfps(60)
# Create circle
circle = gl.createcircle()
circle.set_radius(50)
circle.set_background(255, 0, 0, 255)
circle.set_border(0, 0, 0, 255, 3)
x = 0 # ball pos
going_left = False
running = True
while running:
# Handle closed window
if gl.window_closed() or gl.key_pressed() == ord('q'):
running = False
dt = gl.getdt() # DeltaTime
total_time += dt
# Change direction
if x == width:
going_left = True
elif x == 0:
going_left = False
# Move ball
if going_left == True:
x -= 5
else:
x += 5
# Draw ball
circle.set_pos(x, height // 2)
circle.draw()
# Present scene
gl.present()
# Clear screen
gl.clear()
# Cleanup
gl.cleanup()
print(f'Animation was ran for: {round(total_time, 1)}s')GL is licensed under MIT license. For more details see LICENSE.txt