Methods

createCanvas(width, height, preferDOMopt) → {Canvas}

Create a blank 2D canvas of a given width/height.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber

The canvas height in pixels

heightnumber

The canvas width in pixels

preferDOMboolean<optional>
false

If false, return "Offscreen" canvas

Returns:

The resulting Canvas object

Type: 
Canvas

createCtx(width, height, offscreenopt) → {Context2D}

As above, but returing the 2D context object instead of the canvas. Note ctx.canvas is the canvas for the ctx, and can be use as an image.

Parameters:
NameTypeAttributesDefaultDescription
widthnumber

The canvas height in pixels

heightnumber

The canvas width in pixels

offscreenboolean<optional>
offscreenOK()

If true, return "Offscreen" canvas

Returns:

The resulting Canvas's 2D context

Type: 
Context2D

imagePromise(url) → {Promise}

Return a Promise for getting an image.

use: imagePromise('./path/to/img').then(img => imageFcn(img)) or: await imagePromise('./path/to/img')

Parameters:
NameTypeDescription
urlstring

URL for path to image

Returns:

A promise resolving to the image

Type: 
Promise

setCtxImage(ctx, img)

Fill this context with the given image, resizing it to img size if needed.

Parameters:
NameTypeDescription
ctxContext2D

a canvas 2D context

imgImage

the Image to install in this ctx

toWindow(obj)

Merge a module's obj key/val pairs into to the global/window namespace. Primary use is to make console logging easier when debugging modules.

Parameters:
NameTypeDescription
objObject

Object who's key/val pairs will be installed in window.