Skip to main content

Graphics library

Project description

PIX (pixpy)

A graphics library with a python interface. Designed for learning and 2D game development.

  • Uses OpenGL/GLES2 to make it fast and portable
  • Efficient Console/TileSet rendering for tile or text based games
  • Composable Images using only GL textures

Install

pip install pixpy

For Linux, we need to build from source so dependencies must be installed first;

sudo apt install libxinerama-dev libxi-dev libxrandr-dev libxcursor-dev

The Basics

The following is a full program that opens a window and draws a circle;

import pixpy as pix
screen = pix.open_display(size=(1280,720))
screen.circle(center=(640,360), radius=300)

NOTE: This simple example works because pix is smart enough to "swap" the screen to automatically display what you have drawn, and then leave the window open and wait for the user to close the window, before the script ends.

Normally you create your own main loop and do this yourself;

import pixpy as pix

screen = pix.open_display(width=1280, height=720)

x = 0
while pix.run_loop():
    screen.clear()
    screen.circle(center=(x,360), radius=x/4)
    x += 1
    screen.swap()

To read the keyboard and/or mouse, you can use is_pressed() or was_pressed()

import pixpy as pix

screen = pix.open_display(width=640, height=480)

background = pix.load_png("data/background.png")
sprite = pix.load_png("data/ufo.png")

pos = pix.Float2(screen.size.x/2, screen.size.y - 50)

while pix.run_loop():
    screen.draw(image=background, size=screen.size)
    if pix.is_pressed(pix.key.RIGHT):
        pos += (2,0)
    elif pix.is_pressed(pix.key.LEFT):
        pos -= (2,0)
    screen.draw(image=sprite, center=pos)
    screen.swap()

For more advanced needs you use events

import pixpy as pix

screen = pix.open_display(width=1280, height=720)
canvas = pix.Image(size=screen.size)

while pix.run_loop():
    for e in pix.all_events():
        if type(e) == pix.event.Click:
            canvas.context.filled_circle(center=e.pos, radius=15)
    screen.draw(image=canvas)
    screen.swap()

The Console

A major part of pix is the Console

In its simplest form, it can be used for text output

The console needs to be drawn to be visible, just like everything else.

import pixpy as pix

screen = pix.open_display(width=1280, height=720)
con = pix.Console(cols=80, rows=50)
con.write('Hello\n')
con.render(screen)

console.read_line() can be used to read lines of text. The result will be posted as a TextEvent.

import pixpy as pix

screen = pix.open_display(width=1280, height=720)
con = pix.Console(cols=40, rows=25)
con.write('What is your name?\n')
con.read_line()
while pix.run_loop():
    match pix.get_event():
        case pix.event.Text(text):
            con.write("Hello " + text)
            con.read_line()

    con.render(screen)
    screen.swap()

The Core Objects

  • A Float2 is a 2D dimensional vector with an x and y field that are used to represent 2D coordinates and vectors.

  • An Image is a reference to a rectangular array of pixels on the GPU, or in other words, a set of 4 UV coordinates (known to form a rectangle) and a texture reference.

  • The Screen represents the window or display.

  • A Context ties together rendering state with a rendering target. The Screen, and all Images, can be treated as context and can be drawn to.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixpy-0.1.6.tar.gz (499.2 kB view hashes)

Uploaded Source

Built Distributions

pixpy-0.1.6-pp39-pypy39_pp73-win_amd64.whl (718.8 kB view hashes)

Uploaded PyPy Windows x86-64

pixpy-0.1.6-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (832.3 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

pixpy-0.1.6-pp38-pypy38_pp73-win_amd64.whl (718.6 kB view hashes)

Uploaded PyPy Windows x86-64

pixpy-0.1.6-pp38-pypy38_pp73-macosx_10_15_x86_64.whl (832.4 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

pixpy-0.1.6-pp37-pypy37_pp73-win_amd64.whl (718.5 kB view hashes)

Uploaded PyPy Windows x86-64

pixpy-0.1.6-pp37-pypy37_pp73-macosx_10_15_x86_64.whl (832.2 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

pixpy-0.1.6-cp311-cp311-win_amd64.whl (719.0 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pixpy-0.1.6-cp311-cp311-win32.whl (624.2 kB view hashes)

Uploaded CPython 3.11 Windows x86

pixpy-0.1.6-cp311-cp311-macosx_11_0_arm64.whl (760.6 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

pixpy-0.1.6-cp311-cp311-macosx_10_15_x86_64.whl (820.5 kB view hashes)

Uploaded CPython 3.11 macOS 10.15+ x86-64

pixpy-0.1.6-cp310-cp310-win_amd64.whl (719.0 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pixpy-0.1.6-cp310-cp310-win32.whl (624.3 kB view hashes)

Uploaded CPython 3.10 Windows x86

pixpy-0.1.6-cp310-cp310-macosx_11_0_arm64.whl (760.6 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

pixpy-0.1.6-cp310-cp310-macosx_10_15_x86_64.whl (820.6 kB view hashes)

Uploaded CPython 3.10 macOS 10.15+ x86-64

pixpy-0.1.6-cp39-cp39-win_amd64.whl (712.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pixpy-0.1.6-cp39-cp39-win32.whl (624.4 kB view hashes)

Uploaded CPython 3.9 Windows x86

pixpy-0.1.6-cp39-cp39-macosx_11_0_arm64.whl (760.6 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

pixpy-0.1.6-cp39-cp39-macosx_10_15_x86_64.whl (820.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.15+ x86-64

pixpy-0.1.6-cp38-cp38-win_amd64.whl (719.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pixpy-0.1.6-cp38-cp38-win32.whl (624.4 kB view hashes)

Uploaded CPython 3.8 Windows x86

pixpy-0.1.6-cp38-cp38-macosx_11_0_arm64.whl (761.1 kB view hashes)

Uploaded CPython 3.8 macOS 11.0+ ARM64

pixpy-0.1.6-cp38-cp38-macosx_10_15_x86_64.whl (820.9 kB view hashes)

Uploaded CPython 3.8 macOS 10.15+ x86-64

pixpy-0.1.6-cp37-cp37m-win_amd64.whl (717.2 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pixpy-0.1.6-cp37-cp37m-win32.whl (625.6 kB view hashes)

Uploaded CPython 3.7m Windows x86

pixpy-0.1.6-cp37-cp37m-macosx_10_15_x86_64.whl (815.2 kB view hashes)

Uploaded CPython 3.7m macOS 10.15+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page