Graphics library
Project description
PIX (pixpy)
A graphics library with a python interface. Designed for learning and 2D game development.
Install
pip install pixpy
For Linux pip builds from source so you need a few dependecies;
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(width=1280, height=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.3-pp39-pypy39_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fc74ecc14bf57ac44d116c9d7680efa0d00650d4542d45b7c0357be755e2969 |
|
MD5 | 34b3d999c7d2348d3307de9d1df20616 |
|
BLAKE2b-256 | 43958630d25a12c1345967e6d3dd6ad5ea6da26863b6912280fc4466af162099 |
Hashes for pixpy-0.1.3-pp39-pypy39_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87485737daf2e66e5e4a26bf5581f527fe2d2fda7344aabaa620829eec088f60 |
|
MD5 | 9d7032cd2e74ef2d1bbf70f21468ed96 |
|
BLAKE2b-256 | 68234150e1211adc157968acc471126f6c126a3f444425a72e255ffb56dca964 |
Hashes for pixpy-0.1.3-pp38-pypy38_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f71406519f3139e1732fdcacd8a90f9d73a55d84317133e3c2511ec9db6165b6 |
|
MD5 | 7af0dcb9084d2576dbdad4559ea19126 |
|
BLAKE2b-256 | 56b0ecc723f367ceec5a76016cfc9fb62417af6181d93b294e0c65e01d477f05 |
Hashes for pixpy-0.1.3-pp38-pypy38_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10eb3d6f0ab569cac70872fd8f19c7eb74afd2ef416b08729ad25e10662c820a |
|
MD5 | 6d364f0e59a7d7136522d1a535c18d3b |
|
BLAKE2b-256 | dbcb73fd80f650062c7d100ad9991a5a4480c184ec55e4bff1fa51c2316a5f64 |
Hashes for pixpy-0.1.3-pp37-pypy37_pp73-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c984ba86a6adf1cbea5a37543c18d42f4d4dee5a428ce8dc280dd2b5bc78536 |
|
MD5 | 3b640ce7def35de39668130f922c545c |
|
BLAKE2b-256 | 4f374c66ce7ad9bed11bd9165e1736e7781fce2c3caa377604624aee36b766b7 |
Hashes for pixpy-0.1.3-pp37-pypy37_pp73-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3c4c88de5a5b11963d54c80cf6ef4389dbde294652bad7be5ad9915881a65b64 |
|
MD5 | 6944aa95201cb16645e06fe6f042dc95 |
|
BLAKE2b-256 | bcc8c2b67835fcf8ff67af16ebe1e2a6ab8e950bbafb2a3fdad4b26bac21cfcb |
Hashes for pixpy-0.1.3-cp311-cp311-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d3006247ddb18c5905f11e175f2497ed7ad60e72dfaa11333cc67a0147b870d |
|
MD5 | 88e191a4d588a563d820a1cd4ec0d34c |
|
BLAKE2b-256 | 2396b5374e114131aa727ef287bff9bc55e46d60105f9535d458375787643e16 |
Hashes for pixpy-0.1.3-cp311-cp311-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5468d33f0794e2c38941f1eb4db8164959a38fe95f51e492a7ced59901b76230 |
|
MD5 | 36abf558a3f51a2155aaad271c42f217 |
|
BLAKE2b-256 | a4f693f41d525794f85c17d587a16d256d62f354faf915a46b75391b019a4e5a |
Hashes for pixpy-0.1.3-cp311-cp311-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42240b02c31f4e88d4b85c7eec6e767196e679e17389e40294968d643ddce33f |
|
MD5 | 01ab64468cd250cd4df51e81b1ca92c6 |
|
BLAKE2b-256 | 86c6eb33c50fa62a9689b23be0ba827abdbaa289868afbab767306462a2723a9 |
Hashes for pixpy-0.1.3-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c682cf8646b1cdee4da70e351dad947c91507f5c25cdc70ace635dc02b78599d |
|
MD5 | e988319f1aa32c607d275cbb5c339d0e |
|
BLAKE2b-256 | f08a7ae374375d504a3585413bd7196b1cfa5c63c22dcf9b0c7741c92ada1839 |
Hashes for pixpy-0.1.3-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df746e45cdb6e80d2152ed8a27be893dbed619b8b82e9930f68b30e6a07dfddb |
|
MD5 | 130eaa8f87e2174e1587da45d01f1ba3 |
|
BLAKE2b-256 | 3a9cb0f5bdea92f518060055e8034bbf5a85f2cc1a081b651383597cbe16d74f |
Hashes for pixpy-0.1.3-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 014ca2ab32ea5a24fb4e2963cb3e60f27bebdd30fa3969275b7489af72b06f4e |
|
MD5 | d76cec3172551f58722dc6b67a5c49cd |
|
BLAKE2b-256 | 2b0648c80078d4012db4b9079119b20661bd11e53ef8854bb5a22194a0b1f51e |
Hashes for pixpy-0.1.3-cp310-cp310-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76eefe1732b35d2c6243519b12376e4a07ab7cfa0bd1841fbe34cef96424673e |
|
MD5 | 607d2bcc385b52ab9133bb1488e44d24 |
|
BLAKE2b-256 | 6c285c83ec60da138b35220beff660d35d6fe22c9f7621823e306e602f5101fa |
Hashes for pixpy-0.1.3-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ad80890c18a63f7d34de8288c534b77a46c0fb425890ebc0bd69336b68fe217 |
|
MD5 | 68754adf499ce722cb7fd4d40be8ae61 |
|
BLAKE2b-256 | bedbdfd78cb74efc5a8a6acecbacd53b71c5fd757042c2ce8650007acea906a5 |
Hashes for pixpy-0.1.3-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21814d86b0222ddf308bbcbb124fa5cb4a4ac45c78db7f15f8ade7e9e7ef8445 |
|
MD5 | 7af9b5b8503d381a1081097e6d58d721 |
|
BLAKE2b-256 | 779ac273af809ed22c753c5927b7d56ecfdc7e3fbbb62b3f7d1bc6fd1d200fab |
Hashes for pixpy-0.1.3-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98ad351180d52f44caea72025709274620b24af43d5afe924a97579dcfe8a9b4 |
|
MD5 | 38020cd76cd04343cf9e89a4bf22ce66 |
|
BLAKE2b-256 | d70430a14e216bf48bd3a85080e2af2a27da9feed1a9c6e2c27eb71f006daa4f |
Hashes for pixpy-0.1.3-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b2594b8dd066ad8b7112b1a006cc203e02bede10c52bee7a02652b38294a40e |
|
MD5 | ecd8145bc41bd802c571c0d2b3062a89 |
|
BLAKE2b-256 | 6454a35076181f39917cc6c518e88275602712ab0dfd7e97e0c1659753021294 |
Hashes for pixpy-0.1.3-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d782d7457be6ca8328969147fa960a95c5e6d6851161433dedb23727f20fc9c5 |
|
MD5 | 0f771022a9f406ecd06b996bff2e1c50 |
|
BLAKE2b-256 | 5951b30f727781c575e9514f21f2f61993c869a27a3a4cd4cd588a78ce2edbe8 |
Hashes for pixpy-0.1.3-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15bec07ff4f30a0cc74ef4b7aa84c3276db01c1664a353d2abe5af87f70bc702 |
|
MD5 | 71206db2d46459794dfd3d25d5b70234 |
|
BLAKE2b-256 | 4f1a1016061134b8484aeb5cd2d769609ffbc014af2f8b30ac72efb59ae8b73a |
Hashes for pixpy-0.1.3-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b812d495e114bd7a2b29c8e10af19d9c5f42b5e303375a7901251d95c3430a2e |
|
MD5 | 201df7d965160e86477d29848b753692 |
|
BLAKE2b-256 | f19f50c9b279bdc146b2057a9c276129ba96407d3100d4409c364edea6a15b71 |
Hashes for pixpy-0.1.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9a69b0da88b4614670da2359f8b1867726b6b376bebc76bf8e8982b762e577e |
|
MD5 | 4b1225fbea54e6f50c319fd005a1cd3d |
|
BLAKE2b-256 | 844e54e4f8cfe7b17e5e838c9e78d53bb2c169effd6d29c2e961391ecc20764b |
Hashes for pixpy-0.1.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08c15178723662295f2934b3d4fdc87cd8ef7d160327351bb3e757985515be72 |
|
MD5 | 3985f4a989047f7a314d4af1cc612a85 |
|
BLAKE2b-256 | 6abd63f19b0d5751e7481cdca4ad684c11fca331780e3c8ee4f727d5062a806a |
Hashes for pixpy-0.1.3-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 107d82c0cb3e8ea3e874e74853f9a240ae294443c0fae59a700d17791c2d8e42 |
|
MD5 | a111123f69f7c278b130cea1fd0c311b |
|
BLAKE2b-256 | 1f564fc936d4244c087d50782e143ca3e20dae970d49afb4ae657349811d6ca8 |