Skip to main content

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.Grid(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()

Updates

0.2.0.1

  • Reupload due to issue with first upload of 0.2.0.

0.2.0

  • Updated grid initialisation.
  • Added text as a UI option.
  • Added image caching to speed up programs.
  • Other code refactoring and minor changes.

0.1.0 (Mistakenly uploaded to PyPI as 0.1.1)

  • Added the ability to force a window size and set the position of the grid in relation to this as desired.
  • Added the possibility for UI elements.
  • Added methods to Grid to get global coordinates from grid coordinates or vice-versa
  • Other minor changes

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.2.0.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

pygrille-0.2.0.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file pygrille-0.2.0.1.tar.gz.

File metadata

  • Download URL: pygrille-0.2.0.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.1

File hashes

Hashes for pygrille-0.2.0.1.tar.gz
Algorithm Hash digest
SHA256 cfde5bf544f8b421bf31aee4d5de60208a3ee5f3828adac1887c8ffa11ff77d5
MD5 bfce241b756d72ca71793f0fa713e334
BLAKE2b-256 8bf59f54a94261f178bfb3b08e5215364b9c028b21b0347742843d66d2d6fa6c

See more details on using hashes here.

File details

Details for the file pygrille-0.2.0.1-py3-none-any.whl.

File metadata

  • Download URL: pygrille-0.2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.1

File hashes

Hashes for pygrille-0.2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7526a56d715623bc08cc113180a96e8013776180617eb21dfb724fe350a59c05
MD5 af98ae484abe1ea1d8740df774690350
BLAKE2b-256 f10723d0d9b42acd87b1f6006f5c181616742543ee7ac2fa39e01a0a867aa66b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page