Alexandre B A Villares


pyp5js gameboards

A repo with examples for using pyp5js to make simple games

pyp5js is a wonderful project that combines Python in your browser (with pyodide) and the drawing infrastructure of p5js.org, you chan check the online demo editor here. The drawing function names and global variable names are mostly those of p5js, but function setup(){} & function draw(){} become def setup(): & def draw():, because, well, we love Python!

This repository collects code examples for using pyp5js to teach and to play simple board games. If you make one, feel free to make a Pull Request. I ask everyone to abstain from submiting materials unsuitable for children, as we’d like this repository to be used for teaching.

If you enjoy this you can make a small donation to support my work!

A chess set with emojis

image

editor + code PT names/comments

sketch-only page

A multipurpose demo example

image

...
grid = True    # draw a grid
w = 100        # grid cell width 
cols = 8       # number grid of collumns
rows = 8       # number grid of rows
chess = False  # True makes grid cells alternate black and white

img_url = 'https://i.ibb.co/RCPfVkc/199727104-be1a69fa-1e44-47b2-8778-56f7f257c96b.png'
background_image = False  # True will load the image from the URL above

dice = None   # not visible
n_dice = 10   # this is a d10, d6 are special!
...
    # Describe pieces here!
    pieces = [
      # [symbol, color, col, row, degrees_rotation],
        ['▲', 'blue', 0, 1, 90], 
        ['🐊', 0, 0, 0, 0],       # you can also use 0 to 255 for grays
        ['♜', 'red', 1, 0, 0],    # or color(R, G, B), for colors
        ['◼', 'green', 1, 1,0], 
    ]
...

editor + code EN names/comments