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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file pygrille-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: pygrille-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.4 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 | a115e7ede9cbb464fa6f56dcec86f6ebc910b4cb3a76c5af9e16dcd71a600520 |
|
MD5 | 6e9744245979919b1cbd3a3c91faf1ee |
|
BLAKE2b-256 | 6c6ecefe7cafc9d903060c5ca477012fe5df57345db04010907df536a2d1be7d |