Skip to main content

Simple tool to allow to transcrypt Python code that uses P5.js

Project description

Python to P5.js Transcriptor

This project started from a proof of concept based in Axel Tanner's "Transcrypt & p5js" blogpost. The project's main goal was to use Tanner's approach combined with decorator and global variables control to enable P5.js API from being called "directly" from the Python code as clean as possible.

Here's an example of a valid Python code using P5.js API:

from pytop5js import *

def setup():
    createCanvas(200, 200)
    background(160)


def draw():
    fill('blue')
    background(200)
    r = sin(frameCount / 60) * 50 + 50
    ellipse(100, 100, r, r)


start_p5(setup, draw)

Installation

This project requires Python 3 and is now on PyPI, so you can install it with pip or pip3, depending on your environment:

$ pip install pyp5js

Usage

Since you'll be writting Python code and then generating the correspondent P5.js code from it, pyp5js provides a simple command line API to help you to generate the files.

So, to start a new sketch, you'll have to run:

$ pyp5js new my_sketch

This command will create a directory with the following code structure:

~ my_sketch/
  ~ static /
    - p5.js
  - index.html
  - my_sketch.py

The index.html is prepared to display your sketch, so you'll have to keep on opening it to refresh see results from the code you'll add to my_sketch.py.

After updating your code, you'll have to run the transcrypt command to update the files. Run it as:

$ pyp5js transcrypt my_sketch

The way the code is implemented, for now, you'll have to execute it from the same directory-level where my_sketch is - you can't run it from inside the my_sketch directory.

If you're lazy as me, you can use the monitor command instead of the previous one. The command will monitor your sketch directory and keep track of any changes on any .py files. When it notices a new change, it automatically runs the transcrypt process for you. So, now you'll just have to refresh your index.html file to see the results.

$ pyp5js monitor my_sketch

All of the command-line interface methods have a few optional arguments and you can check them by running:

$ pyp5js --help

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

pyp5js-0.0.3.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

pyp5js-0.0.3-py3-none-any.whl (548.1 kB view details)

Uploaded Python 3

File details

Details for the file pyp5js-0.0.3.tar.gz.

File metadata

  • Download URL: pyp5js-0.0.3.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pyp5js-0.0.3.tar.gz
Algorithm Hash digest
SHA256 faa0216b94ac3b98e948ee94c9b84de17865bf70a660973a7a1fc23058933ab7
MD5 d4de489d2374f7b752b0cb13b5571b47
BLAKE2b-256 642d2a0d79b59c3c4289de1be5d1f6a69d723405ceba92485034a617a136a83d

See more details on using hashes here.

Provenance

File details

Details for the file pyp5js-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: pyp5js-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 548.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for pyp5js-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 f3d32953a3903f6df7d929c04a1d2cae2b9ed651c3827faa7922a6a95aea4876
MD5 363c597c15e2ea38dc59d22ba9ba6318
BLAKE2b-256 34312053a83114ca2cb4aa461cf5a2d2672f18c87c2ced3cd7dfc8f12dc6e806

See more details on using hashes here.

Provenance

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