ipyp5

Version: 0.2.0.dev

p5.js Jupyter Widget

Quickstart

To get started with ipyp5, install with pip:

pip install ipyp5

Contents

Installation

The simplest way to install ipyp5 is via pip:

pip install ipyp5

When using Jupyterlab, install the extension with:

jupyter labextension install jupyter-p5

Introduction

Examples

This section contains several examples generated from Jupyter notebooks. The widgets have been embedded into the page for demonstrative pruposes.

p5.js in Jupyter

In [1]:
from ipyp5 import Sketch
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-0b065d34f2c3> in <module>
----> 1 from ipyp5 import Sketch

ImportError: No module named 'ipyp5'
In [2]:
w = Sketch()
w.value = """
    const [W, H] = [400, 400];
    p.setup = function () {
      p.createCanvas(W, H);
      p.rectMode(p.CENTER);
    }

    p.draw = function () {
      p.background('#ddd');
      p.translate(200, 200);
      for (let i = 0; i < 4; i++) {
        p.push();
        p.rotate(p.frameCount / 200 * (i + 1));
        p.fill(i * 5, i * 100, i * 150);
        p.rect(0, 0, 200, 200);
        p.pop();
      }
    }
"""
w
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-ef2f2f718753> in <module>
----> 1 w = Sketch()
      2 w.value = """
      3     const [W, H] = [400, 400];
      4     p.setup = function () {
      5       p.createCanvas(W, H);

NameError: name 'Sketch' is not defined

Developer install

To install a developer version of ipyp5, you will first need to clone the repository:

git clone https://github.com/jupyter/ipyp5
cd ipyp5

Next, install it with a develop install using pip:

pip install -e .

If you are planning on working on the JS/frontend code, you should also do a link installation of the extension:

jupyter nbextension install [--sys-prefix / --user / --system] --symlink --py ipyp5

jupyter nbextension enable [--sys-prefix / --user / --system] --py ipyp5

with the appropriate flag. Or, if you are using Jupyterlab:

jupyter labextension install .