Skip to main content

PXNG

PXNG is a python library that provides a simplified API for working with pixels, drawing shapes, writing text and interacting with input devices. It is inspired by the olcPixelGameEngine by OneLoneCoder.

What it can do:

  • Create a window for drawing. The window supports rendering at a lower virtual resolution.
  • Render text. The built in font is C64 styled.
  • Render filled shapes. Currently only rectangles. :)
  • Render sprites. Sprites can be scaled and blend with the background. Created from NumPy arrays. It is also possible to use imageio to read files directly in to sprites. Any changes in the data buffer of the sprite can be updated in the live rendering.
  • Animated sprites. Using a sprite sheet pxng supports animation.
  • Poll the keyboard for events.

How to install

Installation of pxng is done simply by: pip install pxng. The examples are not part of the distribution.

Getting started

Before venturing into the examples, let us try a Hello, world! example first.

import pxng
from pxng.colors import *

This will import the pxng library and get some named colors that we can use.

if __name__ == '__main__':
    window = pxng.Window(640, 480, 'PixelEngine', scale=2, vsync=True)
    window.set_update_handler(update)
    window.start_event_loop()

This will create a 640x480 window with a scale of 2. This scaling factor results in a virtual resolution of 320x240. We set vsync=true to limit the frame rate to 60 frames per second (Hz). Finally we set the update handler to point to a function we have not made yet, called update.

def update(window: pxng.Window):
    window.draw_text(100, 100, "Hello, world!", tint=LIGHT_GREEN)

The update function has a single argument that is provided by the framework and it is window. This is the context that you will use to draw and handle interaction. In this case we use the draw_text function to write our "Hello, world!" message at (x, y) = (100, 100) in a light green color.

Running this should result in the following screenshot:

Screenshot of text_rendering.py

Examples

In the examples folder there are three applications that show how the library is used to perform different tasks. These examples does not show the most efficient way of doing the task, however.

  1. Palette - By abusing fill_rect the following screenshot was created. The live rendering animates the color of the lower HSL view and all of the RGB views.

Screenshot of palette.py

  1. Animated Sprites - Shows some of the possibilities of rendering sprite sheets. All of the visible sprites in the screenshot are animated by sub indexing the sprite sheet in a 8x8 grid. Left click and drag to move one of the sprites (the largest running character) around.

Screenshot of animated_sprites.py

  1. Text Rendering - This example shows animated rendering of text. The green field of hexadecimal numbers scrolls by as fast as it can. Press space to stop the animation. Use the up and down arrow keys, page up and page down or home and end to navigate in the scrolling text. Mouse scrolling is also supported.

Screenshot of text_rendering.py

Copyrights

Credits

  • thekingphoenix and Bonsaiheldin for the character sprite
  • para for particle effects

Metadata

Release files for pxng 0.0.13

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pxng 0.0.13
File Size Uploaded
pxng-0.0.13.tar.gz 31.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pxng 0.0.13
File Interpreter ABI Platform
pxng-0.0.13-py3-none-any.whl Python 3 none any Details

Total release size: 66.2 kB

Release files / pxng-0.0.13.tar.gz

Download URL pxng-0.0.13.tar.gz
Size 31.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9270e08217484b6927b0df8045823fa28eb1914be206f8437c3330bc03a1d459
BLAKE2b-256 checksum
How to use checksums
97abd71c7a1b6d6840a032142601416ffdd2140c30c746cc5a4c17498e7d8a80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release files / pxng-0.0.13-py3-none-any.whl

Download URL pxng-0.0.13-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fbd234c29a07d2b0c89dc2beb3f9fa2d4049a039ab19cefab92b6b69a02d004e
BLAKE2b-256 checksum
How to use checksums
7aa2442e149fe0c52f4a879bf84067cb633d29feacb0fc5377eff13158f70e2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0.post20201006 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.13 This release

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page