a library for manipulating OffscreenCanvas with p5
npm install p5.offscreencanvasp5.OffscreenCanvas.js file in dist folder and put it in your project.Important it should be loaded after p5, your index.html file should look something like this
```
...
...
This little wrapper provides a new function createOffscreenCanvas, which return a p5.Graphics-like object. It can be used to draw things off screen with the OffscreenCanvas Object instead of creating a new canvas in the dom tree. The OffscreenCanvas object can be also use in worker thread. This library also overwrite the image function for the 2D renderer to allow it to display ImageBitmap and OffscreenCanvas object.
See files in the example folder for more information.
) in dist folder. You can use it to start your project with web worker. You can find more about how to do it in the code comments.API
$3
Type: functionArguments:
width, height, [renderer = P2D]Create a new wrapper object (of class
OC) of a OffscreenCanvas object with the given width and height.$3
Type: functionArgument: none
Reset the offscreen canvas context matrix.
$3
Type: functionArgument: none
Remove this offscreen canvas from the p5 instance.
$3
Type: functionArgument: none
Return: a ImageBitmap object
Return a bitmap image of the current render of the offscreen render this action will transfer all content in the canvas to the ImageBitmap object.
$3
Type: functionArguments:
{object}
options: an object containing the options, see https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/convertToBlob {function}
callback: an callback to handle the promiseReturn: A
Promise returning a Blob object if a callback is not specified, else undefined.Create a Blob object representing the image contained in the canvas
$3
Type: function
Argument: none
Return: The OffscreenCanvas Object
Return the transferable OffscreenCanvas object.
$3
Type: function
Argument:
{OffscreenCanvas}
comingCanvas`Load a transferable OffscreenCanvas object. This action will create a new renderer if the loaded canvas' drawing context is different from the current one. Else the drawing context properties (e.g. fill and stroke color in 2d context) are also loaded. This action will not copy the OffscreenCanvas object.