simple graphics GitHub

Make the idea
visible.

Simple Graphics is a small, readable layer over Pygame. Define shapes, decorate behavior, and let your program become a window.

v0.0.11Python 3.9+MIT licensed
scene.py
every shape
starts as an idea
x 300   y 300
@on_tick def simulate():
planet.x += velocity

01 / Start here

Getting Started
three moves.

Install the package, make a thing, give it a heartbeat. Objects appear as soon as you create them.

01

Install

Get the package from PyPI.

pip install simple-graphics-lib
02

Compose

Shapes register themselves in the scene.

from simple_graphics import *

ball = Circle(140, 120, 24,
              color="#ff6b4a")
03

Run

Decorators connect your logic to the loop.

@on_tick
def update():
    ball.x += 2

run(400, 300)
A complete first scene

Paste this into a file and run it with Python.

from simple_graphics import *

ball = Circle(80, 120, 24, color="#ff6b4a")

@on_tick
def move():
    ball.x += 2
    if ball.x > 400:
        ball.x = 0

run(width=400, height=240, caption="A small beginning")

02 / The visual vocabulary

Drawing Shapes

Every shape is a live Python object. Change its properties inside an event and the next frame reflects it.

Rect

Rect(x, y, width, height)

Rectangles, panels, paddles, cells, and buttons.

Circle

Circle(x, y, radius)

Round bodies for balls, planets, and markers.

Polygon

Polygon(points)

Build custom silhouettes from a list of vertices.

Line

Line(points, width=10)

Connect points into paths, hands, and boundaries.

Hello.

Text

Text(x, y, text)

Render labels and live game state in the scene.

IMG

Image

Image(x, y, img_path)

Load, scale, and rotate an image asset.

Shared shape controls

color   visible   draggable   is_obj_over()

Open the reference

03 / Give it a heartbeat

Event Handling

Use a decorator to say when a function should run. Simple Graphics handles the Pygame event loop for you.

event.py
@on_tick
def update():
    ball.x += velocity
    ball.y += gravity

04 / Under the hood

Simple Graphics
vs. Pygame.

Simple Graphics is built on Pygame, but provides a higher-level API for common beginner graphics tasks. Here is the same work in both libraries.

Draw a circleSimple Graphics
from simple_graphics import Circle, run

circle = Circle(200, 200, radius=50,
                color="red")
run(400, 400)

Create a shape, then let run() manage the window and main loop.

Draw a circlePygame
pygame.init()
screen = pygame.display.set_mode((400, 400))
clock = pygame.time.Clock()

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    screen.fill("white")
    pygame.draw.circle(screen, "red",
                       (200, 200), 50)
    pygame.display.flip()
    clock.tick(60)

Initialize the display, process events, draw each frame, and control the frame rate.

Handle inputSimple Graphics
from simple_graphics import on_press, run

@on_press("space")
def pause():
    print("Space pressed")

run()

Decorators connect input directly to the function that responds to it.

Handle inputPygame
for event in pygame.event.get():
    if event.type == pygame.QUIT:
        running = False
    elif (event.type == pygame.KEYDOWN
          and event.key == pygame.K_SPACE):
        print("Space pressed")

Inspect each event and compare its type and key inside the event loop.

Pygame provides lower-level control over rendering, timing, and events. Simple Graphics reduces that boilerplate so you can focus on the behavior of your program.

05 / Keep close

The compact
reference.

These are the pieces you will reach for most often while building.

Scene controls

run(...)Start the window and main loop.
set_bg(color)Set the background color.
clear_screen()Remove every shape.
erase(shape)Remove one shape.
is_colliding(a, b)Check whether two shapes overlap.

State helpers

mouse.x / mouse.yRead the current pointer position.
game.any_nameStore shared mutable game state.
Group(a, b, ...)Move and query shapes together.
shape.visibleKeep a shape in the scene but hide it.
shape.rotate(angle)Rotate supported shapes in degrees.