A wrapper for the Discord Python Pixels API.
Project description
PyDisPix
A simple wrapper around Python Discord Pixels.
Requires Python 3.9+ (3.x where x >= 9).
Requires requests
, pillow
and matplotlib
from pip.
Example
import pydispix
# Create a client with your token.
client = pydispix.Client('my-auth-token')
# Let pydispix find your token from `TOKEN` environmental variable
client = pydispix.Client()
# Download and save the canvas.
canvas = client.get_canvas()
canvas.save('canvas.png')
# And access pixels from it.
print(canvas[4, 10])
# Or just fetch a specific pixel.
print(client.get_pixel(4, 10))
# Draw a pixel.
client.put_pixel(50, 10, 'cyan')
client.put_pixel(1, 5, pydispix.Color.BLURPLE)
client.put_pixel(100, 4, '93FF00')
client.put_pixel(44, 0, 0xFF0000)
client.put_pixel(8, 54, (255, 255, 255))
We can also display the image with pillow
canvas = client.get_canvas()
canvas.show()
Or we can display with matplotlib
to see it with coordinates
canvas = client.get_canvas()
canvas.mpl_show()
Auto-draw
Load an image:
from PIL import Image
im = Image.open('pretty.png')
ad = pydispix.AutoDrawer.load_image(client, (5, 40), im, scale=0.1)
ad.draw()
Or specify each pixel:
ad = pydispix.AutoDrawer.load(client, '''0
0
3
2
ff0000
00ff00
0000ff
ff0000
00ff00
0000ff''')
ad.draw()
Format of the drawing plan:
- Leftmost X coordinate
- Topmost Y coordinate
- Width
- Height
- Each pixel, left-to-right, top-to-bottom.
Auto-draw will avoid colouring already correct pixels, for efficiency.
You can also run this continually with guard=True
which makes sure that after your image
is drawn, this keeps running to check if it haven't been tampered with, and fixes all non-matching
pixels.
ad.draw(guard=True, guard_delay=2)
Guard delay is the delay between each full iteration of all pixels. We need to wait since looping without any changes is almost instant in python, and we don't want to put cpu through that stress for no reason
Progress bars
Every request that has rate limits can now display a progress bar while it's sleeping on cooldown:
pixel = client.get_pixel(0, 0, show_progress=True)
canvas = client.get_canvas(show_progress=True)
client.put_pixel(52, 10, "FFFFFF", show_progress=True)
Logging
To see logs, you can set the DEBUG
environment variable, which changes the loglevel from logging.INFO
to logging.DEBUG
You can also do this manually by executing:
import logging
logger = logging.getLogger("pydispix")
logger.setLevel(logging.DEBUG)
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 Distribution
File details
Details for the file pydispix-0.4.2.tar.gz
.
File metadata
- Download URL: pydispix-0.4.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9ba471acd28fafee4f583e00f7fa786b8dc58e73e8a430773111f326e35719a |
|
MD5 | e55783e30bccfafe0e9677ff28e94d41 |
|
BLAKE2b-256 | ad0d09381aa0570f3fcb0b0c32f4b8e275c5dff55c2bea0914e78b13de641a8a |
File details
Details for the file pydispix-0.4.2-py3-none-any.whl
.
File metadata
- Download URL: pydispix-0.4.2-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7b5f1e3f4cef0b98b64967b6a0e67855386c2d104795636264684bc92e2427f |
|
MD5 | 94ed0140c2887cc4c296e099ef1ca5f1 |
|
BLAKE2b-256 | 3922182b9bf11e35fb2464fc49bdf5397d5d0a71a7f02c21967044ebcb1b654c |