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.Vec2(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 Vec2 is a 2D dimensional vector with an x and y field that are used to represent 2D coordinates and sizes.
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for pixpy-0.1.4-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | acbf110a450870d3cec9e3db162b066d48de98afda8b7d9e3136461cf2dd22fd |
|
MD5 | 2b87bb667be0707e6c9f021eb5842799 |
|
BLAKE2b-256 | dfbba373007fa936f4f80d81b6087e7b8ea906da96a5c2c10953228aa1a4e79b |
Hashes for pixpy-0.1.4-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42e285e02aec8c252ac66048fce36d206ad9aa8732e866f62b1f12081a523283 |
|
MD5 | 089cf16fa61919f43f3e256f4b14fd82 |
|
BLAKE2b-256 | 4cd56120cb1e731bdda1ad19e7fec940558de805d76d7bed20be75cde48a6975 |
Hashes for pixpy-0.1.4-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8096570e35cdc0f08b3b2907aee8e5163bcb70b57967600c5f0b5692f11f96ad |
|
MD5 | 6046efb18c6643f56f18e85242f0eb80 |
|
BLAKE2b-256 | f7980a1c626a0c1b2c058fa015d0a4ca7b3d9af0af18048cbd928c502719c774 |
Hashes for pixpy-0.1.4-pp38-pypy38_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2c1d5953cdd7c870416314173746f512e4ed5209470c3ce8801bb9e82b3cbf |
|
MD5 | e02769e828cc4aeee5f3ef62ef16d544 |
|
BLAKE2b-256 | d74d951894f78089363f7889556c5fd87cffa6b35c9d0100d77686557656b889 |
Hashes for pixpy-0.1.4-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57f5586e08ce2b8413243f6aea273eee20dff89242ce11d3ef2f72472992df94 |
|
MD5 | ea4ff24471aa5458dbeef41991e37eff |
|
BLAKE2b-256 | 27cec6da8025e6058c033cc4927ee45be0ad89c16ac527a4f404a90e3b23e6ec |
Hashes for pixpy-0.1.4-pp37-pypy37_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 049cf41a155ccd6bb1102c901367d2ec3ef304cf21f74ee038081e7ca243fbc2 |
|
MD5 | fdefb5b52fa5c383154c8a93065799cc |
|
BLAKE2b-256 | fa590bd21ca18270234e4597abdeb4384b786f5687f38820c5719a7d08d2adcf |
Hashes for pixpy-0.1.4-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc984af39aa9bc7ff818601a4f57075fc97468b6e1f98e35f720b262b57730a6 |
|
MD5 | 88530693a4d9e25007acd871877de5c8 |
|
BLAKE2b-256 | bdcfafc4a12286b47030fe159129c2a112ba117fc04e14e491911b4fe866996d |
Hashes for pixpy-0.1.4-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8103e4f985ba0077a12152b6eeb54c70e8cdbd43edfc22f509bb4025db5da632 |
|
MD5 | 715828dd55d99a66c007ded39f8b1356 |
|
BLAKE2b-256 | c939cf4ad3d7def58bb209dd979fa6757b422e65ba7ade2b76b14367452e99ad |
Hashes for pixpy-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0db0e32e5fd27c49133ff7f1216d92a3bb31d3d19491596fc5383382b626b484 |
|
MD5 | 238821bf566a3eb32318b2f46dc80d87 |
|
BLAKE2b-256 | da897b824477495bcbda5164713f8039593067ea9182677595d42b53efd99215 |
Hashes for pixpy-0.1.4-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9aef2b5c99836583fc9a4679265c99a81b3294c5d97685df6e86972e002d7b6f |
|
MD5 | 04d50638bccccc884f093938539f58fa |
|
BLAKE2b-256 | ad7762fbb8c582564739bb495b1384061ddd5568f308ec4ebe2109fd6a80d4fd |
Hashes for pixpy-0.1.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e882158f2065834b37f589ce520d9dc0be68edb9a2cb48fde1713a726bd40950 |
|
MD5 | a6c7bba27b5e660b2684b3607fab6c4a |
|
BLAKE2b-256 | ec54765ca481b8aea9500cc374df4ec7dc1968e74014e6f5223e24845c72a2bd |
Hashes for pixpy-0.1.4-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7b970e39745388196e0bb91d5ba2c4ee410ac30d6b6c36988c4e224f63444bd |
|
MD5 | 0b13ccde43ae04864713b881c1d6a51f |
|
BLAKE2b-256 | 8956e6b5cb43f8822e5e3bb03aca80a79fce2b948d63c881f40c47f6a4ce32d0 |
Hashes for pixpy-0.1.4-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7117fa34a0849152bca76e2f41cc9b1605b24c5d075e2fbb6563c91d30c6bd0 |
|
MD5 | 5d025658cd07cc146a8cbb3b834bdf57 |
|
BLAKE2b-256 | 7abd0d3a3dc392ae921f6e5d253ec300283b283cf5c6b6a680cdec84dd495ace |
Hashes for pixpy-0.1.4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8b65a8739b559e6625e92b2a2024de33628745f69b8a7bde18d7ea19a19e04b |
|
MD5 | 05f6df550ab62374a9e8122cd1fb1ba8 |
|
BLAKE2b-256 | 99f3c22feae0707ec64049f74b1e7fea3e11e35969bb3b5576bb03368a052fe3 |
Hashes for pixpy-0.1.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6d364e6ec4178dfce4ec00a0851db0e5fde361556896e727608373efb540f9 |
|
MD5 | 4a4067af5d1a0b3ecacade98780b15b8 |
|
BLAKE2b-256 | b3b65b7d4c87b9112ba434f5d6f7fc1bb52963de9a00079623f57d47bec9e2e1 |
Hashes for pixpy-0.1.4-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b66ff528a28e962037fab04ae00de9476cc32db35a00e649a1acfdef89bfb84 |
|
MD5 | 8c7ca1c5daaa9f770bc1f9cdbc7e0705 |
|
BLAKE2b-256 | b80281dcc5f3dda169bb03c7eac32575b9bdbe59646ecca21347ce844fd3fd45 |
Hashes for pixpy-0.1.4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ef2b222eacea5c3951f58e4a5324b3eb1334df26026c7bf7eec7356b139de69 |
|
MD5 | 85f73eec9b5062cad282abbe8407ebef |
|
BLAKE2b-256 | ae3c1b88424982ae15ea05bb591e3ecd8eba751d65e5c4a694accc9e6aedb94c |
Hashes for pixpy-0.1.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bc738d2a448d9d1a4c8b66a28bff42a77b0a309cc8b85902d919a471412c9d9 |
|
MD5 | 909d1add0729aa17c33c4ae4587a7184 |
|
BLAKE2b-256 | 7ada735836af653ecffb5b2968d3b4083cf0f637ade49f79e7294c2e07af3390 |
Hashes for pixpy-0.1.4-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45ed39364c7bd39aff696e0cfeb014460b07531c1b0f28bef59312abc0bf26fd |
|
MD5 | e8044c8cf998b5370b033b166956c043 |
|
BLAKE2b-256 | 3bd9c5eb6a59caebdb7dbf23f5e003382e20ff4bee794391f2adbdb54d180a82 |
Hashes for pixpy-0.1.4-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7aad81ec18934fabfbe1716edb1c7746da91e768c8239d623e41f9d2efbe19a |
|
MD5 | 3b8d35016911be46441668d8e4efac04 |
|
BLAKE2b-256 | 64ead864a87fde814a92ea4f5dfa852c468512f42210c61bcc6c09151a7839b8 |
Hashes for pixpy-0.1.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a814ffa04ead80ea8c5e420c0afef5e3407ab266e281ac2807e96884ae095038 |
|
MD5 | 2d23afbb0574f688e2572a2c0e41d429 |
|
BLAKE2b-256 | 148f96ba3150d5188eb29e2f13b7dbf50e3603efabbebea240f8ca3ced22ffc1 |
Hashes for pixpy-0.1.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3b857ba906df2cf1a30327de890d7684af0c3ac7793353efc755d4b45232e30 |
|
MD5 | 7e3b5d3178430457057228db0b1e0eff |
|
BLAKE2b-256 | c7d3c57fb4702d4f9839c3e80cff406064e16543692acb1ccc329d1ff676dce2 |
Hashes for pixpy-0.1.4-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad452577012a941442a086b2bc2ee84f0fe0b9f911d99f886d32ae2457c89ddd |
|
MD5 | 926ebca38e7f7f9e577b10059e7f90d5 |
|
BLAKE2b-256 | 6cd457ee9f39801b0696bd6a131b909bd08f818e176d689468081ba16e9c1383 |