2d-context

1.3.0 • Public • Published

2d-context

Grabs a CanvasRenderingContext2D, returning null if it doesn't exist. Similar to webgl-context.

var context = require('2d-context')()
var canvas = context.canvas

or

var canvas = document.createElement('canvas')
 
var context = require('2d-context')({
    canvas: canvas,
    alpha: true,
    width: 256,
    height: 256    
})

Usage

NPM

ctx = require('2d-context')([opt])

Gets a new canvas context with optional parameters:

  • canvas a canvas element to use, otherwise creates a new element
  • width a width to set, otherwise no change
  • height a height to set, otherwise no change
  • other attributes are passed to the getContext call, like alpha and storage

You can then get a reference of the canvas element with ctx.canvas.

License

MIT, see LICENSE.md for details.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.0
    13
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.3.0
    13
  • 1.2.0
    1
  • 1.1.0
    1
  • 1.0.2
    1
  • 1.0.1
    1

Package Sidebar

Install

npm i 2d-context

Weekly Downloads

16

Version

1.3.0

License

MIT

Last publish

Collaborators

  • mattdesl