Grabs a CanvasRenderingContext2D, returning null if it doesn't exist. Similar to webgl-context.
var context = require('2d-context')()
var canvas = context.canvasor
var canvas = document.createElement('canvas')
var context = require('2d-context')({
canvas: canvas,
alpha: true,
width: 256,
height: 256
})Gets a new canvas context with optional parameters:
-
canvasa canvas element to use, otherwise creates a new element -
widtha width to set, otherwise no change -
heighta height to set, otherwise no change - other attributes are passed to the getContext call, like
alphaandstorage
You can then get a reference of the canvas element with ctx.canvas.
MIT, see LICENSE.md for details.
