A quick way to write and visualise any code involving grids of squares in python.
Project description
Pygrille
Pygrille is a Python library that uses Pygame to make it easier to do many things involving a square grid.
Installation
Use the package manager pip to install Pygrille.
pip install pygrille
Usage
import pygrille
PIXEL_SIZE = 40 # The size of each square in the grid.
GRID_DIMENSIONS = (6, 5) # The number of squares in the x and y directions in the grid.
# Initiate the grid. PIXEL_SIZE and GRID_DIMENSIONS are required and everything else is optional.
# The extras variable is a list of values that you want contained in each pixel - for example a temporary distance in Dijkstra's algorithm.
grid = pygrille.init(PIXEL_SIZE, GRID_DIMENSIONS, extras = ["Hello", "World"], framerate = 60, default_colour = pygrille.random_colour(), border_width = 10)
# Ensures the grid has not been closed each frame.
# Also updates the newclick and newkey variables (booleans - True if there is a new click or key press)
# And the lastclick (tuple - grid location of most recent click) and lastkey (string - name of most recent key pressed) variables.
while grid.check_open():
# If the user clicks on a square, set it to a random colour and set the border to a random colour.
if grid.newclick:
grid[grid.lastclick[0]][grid.lastclick[1]].colour = pygrille.random_colour()
grid[grid.lastclick[0]][grid.lastclick[1]].extras["Hello"] = "Clicked"
grid.border_colour = pygrille.random_colour()
# If the spacebar is pressed, print the status of the extra value "Hello" in the top left pixel.
if grid.newkey:
if grid.lastkey == "space":
print(grid[0][0].extras["Hello"])
# Draw the grid to the screen
grid.draw()
# Keep the grid running.
grid.tick()
# Once pygrille is closed, finish quitting it.
pygrille.quit()
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
pygrille-0.1.1.tar.gz
(3.9 kB
view details)
Built Distribution
File details
Details for the file pygrille-0.1.1.tar.gz
.
File metadata
- Download URL: pygrille-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cb79e11efad0554cf5a58612111821b9741394be5567d2b0db8dfd34cd26e9e |
|
MD5 | 1906db4c180ce25b9a3b9f036e82f7aa |
|
BLAKE2b-256 | cef9dfb2f843e0a3d22d7af8c83cd1a04c17d3ed94749b78d26a53c34528a332 |
File details
Details for the file pygrille-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pygrille-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d05225ade505bd547026a00863e866175f77e32c87ca2e439c5c183f05449509 |
|
MD5 | 2cbb182881a831f1c910bc7cef93d8f0 |
|
BLAKE2b-256 | 9755b65d40bc76211e13c58d8d7ed6c19c995c7b8a0f7966037c5652404a32df |