Skip to content
/ gl Public

Simple library for Python that allows to create simple 2D animations, games, and visualizations.

License

Notifications You must be signed in to change notification settings

zerfithel/gl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GL - Geometric Library

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.


How to install?

Pre-requisites

python
gcc
sh
  1. Clone this repository:
git clone https://github.com/zerfithel/gl
cd gl
  1. Build the module:
source build.sh

or if you are using Windows:

.\build.bat
  1. Write your .py code and run it while in virtualenv:
. ./venv/bin/activate # if not in venv already
python <code.py>

How to start

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')

License

GL is licensed under MIT license. For more details see LICENSE.txt

About

Simple library for Python that allows to create simple 2D animations, games, and visualizations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published