p5two


Namep5two JSON
Version 0.0.2 PyPI version JSON
download
home_page
SummaryAutomatically launch p5js sketches written in python
upload_time2024-02-20 17:13:46
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords p5js generative art creative coding
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Write your p5js sketches with python and automatically launch them in a new window just by running your script.
* no html
* no javascript
* just python

Also included: autoreload on save!

# Installation
`pip install p5two`


# Usage

open your favourite editor and create a new file `<script.py>` and save it wherever you want

```
from p52 import *

def setup():
    createCanvas(windowWidth, windowHeight)
    stroke(100, 100, 100, 100)
    noFill()


def draw():
    background(51)
    ellipse(mouseX, mouseY, 30, 30)
```

open a terminal, move to the folder where you saved the script and run it with `python3 <script.py>` or just use your editor "run" button if available.

A new window should popup with your sketch!

Bonus: try changing your code and saving, the changes should automatically be reflected in the sketch.


# Extra functionalities
I decided to put some extra functionalities that diverge from standard python and p5js practices because I found them more convenient:
## magic `self`
Tired of having to define vars before `setup()` in order to have them available inside `draw()`? now you can define vars inside a "fake" `self` object like this:
```
from p52 import *

def setup():
    createCanvas(windowWidth, windowHeight)
    stroke(100, 100, 100, 100)
    noFill()
    self.point = (100, 100)


def draw():
    background(51)
    line(0, 0, *self.point)
```

## sketch saving and reloading
when viewing your sketch you can press "s" to save a screenshot of it inside the current folder. Likewise you can press "r" to reload the sketch.

## utility functions
- `canvas()`
creates a canvas without having to specify its dimensions, defaulting to full window size
- `center()`
changes the coordinate system: (0, 0) is now in the center of the sketch and the y-coordinates go upwards

more to come...

## inject js libraries (experimental!)
if you have a js library that you would like to use inside the sketch you can download it and put it into the same folder as your python sketch and use `injectJs('library.js')`. Doing so automatically include the library inside the generated html file.




# How does it work?
This package is heavily inspired by the library pyp5js and leverages transcrypt to compile python to javascript behind the scenes.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "p5two",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "p5js,generative art,creative coding",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/fc/47/924da68691b936608c82ba0d8c07875f872026684056eff6c71648a2cd50/p5two-0.0.2.tar.gz",
    "platform": null,
    "description": "Write your p5js sketches with python and automatically launch them in a new window just by running your script.\n* no html\n* no javascript\n* just python\n\nAlso included: autoreload on save!\n\n# Installation\n`pip install p5two`\n\n\n# Usage\n\nopen your favourite editor and create a new file `<script.py>` and save it wherever you want\n\n```\nfrom p52 import *\n\ndef setup():\n    createCanvas(windowWidth, windowHeight)\n    stroke(100, 100, 100, 100)\n    noFill()\n\n\ndef draw():\n    background(51)\n    ellipse(mouseX, mouseY, 30, 30)\n```\n\nopen a terminal, move to the folder where you saved the script and run it with `python3 <script.py>` or just use your editor \"run\" button if available.\n\nA new window should popup with your sketch!\n\nBonus: try changing your code and saving, the changes should automatically be reflected in the sketch.\n\n\n# Extra functionalities\nI decided to put some extra functionalities that diverge from standard python and p5js practices because I found them more convenient:\n## magic `self`\nTired of having to define vars before `setup()` in order to have them available inside `draw()`? now you can define vars inside a \"fake\" `self` object like this:\n```\nfrom p52 import *\n\ndef setup():\n    createCanvas(windowWidth, windowHeight)\n    stroke(100, 100, 100, 100)\n    noFill()\n    self.point = (100, 100)\n\n\ndef draw():\n    background(51)\n    line(0, 0, *self.point)\n```\n\n## sketch saving and reloading\nwhen viewing your sketch you can press \"s\" to save a screenshot of it inside the current folder. Likewise you can press \"r\" to reload the sketch.\n\n## utility functions\n- `canvas()`\ncreates a canvas without having to specify its dimensions, defaulting to full window size\n- `center()`\nchanges the coordinate system: (0, 0) is now in the center of the sketch and the y-coordinates go upwards\n\nmore to come...\n\n## inject js libraries (experimental!)\nif you have a js library that you would like to use inside the sketch you can download it and put it into the same folder as your python sketch and use `injectJs('library.js')`. Doing so automatically include the library inside the generated html file.\n\n\n\n\n# How does it work?\nThis package is heavily inspired by the library pyp5js and leverages transcrypt to compile python to javascript behind the scenes.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Automatically launch p5js sketches written in python",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/lorenzoferrone/p52"
    },
    "split_keywords": [
        "p5js",
        "generative art",
        "creative coding"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c18410b75a29d907c55404d92bece57b56a6db854f142a911590dc4d774d3671",
                "md5": "f8b68c408f45f566d9cfc3f2632ca330",
                "sha256": "503cfcadf4af2bf0d7bdc7203efd854c1047c9b8dd92c56d2cd1087e3028e543"
            },
            "downloads": -1,
            "filename": "p5two-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f8b68c408f45f566d9cfc3f2632ca330",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 51932,
            "upload_time": "2024-02-20T17:13:41",
            "upload_time_iso_8601": "2024-02-20T17:13:41.410239Z",
            "url": "https://files.pythonhosted.org/packages/c1/84/10b75a29d907c55404d92bece57b56a6db854f142a911590dc4d774d3671/p5two-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fc47924da68691b936608c82ba0d8c07875f872026684056eff6c71648a2cd50",
                "md5": "ca37b23d228e2187cc2cc86e222d402d",
                "sha256": "54ee79fbae9842c7e63ba785aef31763ca296d94a8d92c4d9db720567e8b14f5"
            },
            "downloads": -1,
            "filename": "p5two-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ca37b23d228e2187cc2cc86e222d402d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 51022,
            "upload_time": "2024-02-20T17:13:46",
            "upload_time_iso_8601": "2024-02-20T17:13:46.347102Z",
            "url": "https://files.pythonhosted.org/packages/fc/47/924da68691b936608c82ba0d8c07875f872026684056eff6c71648a2cd50/p5two-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-20 17:13:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "lorenzoferrone",
    "github_project": "p52",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "p5two"
}
        
Elapsed time: 0.19758s