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 pyp5js 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

The project is not under Pypi yet, so you'll have to install it from the git repo. To do so, just run:

$ pip install git+https://github.com/berinhard/pyp5js.git@master  # python 3 only

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

Uploaded Source

Built Distribution

pyp5js-0.0.1-py3-none-any.whl (547.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyp5js-0.0.1.tar.gz
  • Upload date:
  • Size: 8.6 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.1.tar.gz
Algorithm Hash digest
SHA256 9ebd3524bee057d2550e94d180ad031720735c57a1274146d3c1d2cd1382354a
MD5 6af76c6365e85064c78b7d5116ebba1b
BLAKE2b-256 8bf342e90eadf338d422d90dd9001cc60468006eb41f2c313ff315de5592bcaf

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: pyp5js-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 547.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2fbddc91ae6ead77a4efb7416ee5d59941338175e73a94153afa12be5cd105
MD5 52633f2118ee94eb5f9b6c4a19f07ef3
BLAKE2b-256 520c1258e321b5bed6b06423b60626057307954c07c4ebb370695fb5282a1e24

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