Create a PNG image using py5bot and embed the result in the notebook.


example picture for %%py5bot
size(100, 100)
fill(255, 0, 0)
rect(40, 50, 25, 25)


Create a PNG image using py5bot and embed the result in the notebook.

This cell magic uses the same rendering mechanism as the py5bot kernel. For users who are familiar with Processing and py5 programming, you can pretend the code in this cell will be executed as a static Sketch with no draw() function and your code in the setup() function. The first line in the cell should be a call to size().

This magic is similar to %%py5draw in that both can be used to create a static Sketch. One key difference is that %%py5bot requires the user to begin the code with a call to size(), while %%py5draw calls size() for you based on the magic’s arguments.

This magic supports the default renderer and the P2D and P3D renderers. Note that both of the OpenGL renderers will briefly open a window on your screen. This magic is only available when using the py5 kernel and coding in imported mode. The P2D and P3D renderers are not available when the py5 kernel is hosted on an OSX computer.

Code used in this cell can reference functions and variables defined in other cells. By default, variables and functions created in this cell will be local to only this cell because to do otherwise would be unsafe. If you understand the risks, you can use the global keyword to add a single function or variable to the notebook namespace.


%%py5bot [-f FILENAME] [-v VARIABLE]


optional arguments:
  -f FILENAME, --filename FILENAME
                        save image to file
                        assign image to variable

Updated on September 11, 2021 16:51:34pm UTC