get-context
Chainable canvas context api wrapper.
Install
With Node.js:
$ npm install get-context
With Bower:
$ bower install get-context
API
getContext(element, type)
Creates an instance of a chainable canvas context api wrapper. The type
argument may be '2d'
or 'webgl'
. Defaults to '2d'
.
var canvas = document;var context = canvas; context // Outer circle // Mouth (clockwise) // Left eye // Right eye ;
.get(key)
Gets a single context property.
context;// returns #000000
.get(array)
Gets multiple context properties.
context;// returns { fillStyle: '#000000', strokeStyle: '#000000' }
.set(key, value)
Sets a single context property.
context;// returns context
.set(object)
Sets multiple context properties.
context;// returns context
.resize(width, height)
Resizes the canvas element and rendering context respecting the device pixel ratio.
context;// returns context
.getPixelRatio()
Returns the current device pixel ratio, if available. Useful for handling responsive canvas elements and adjusting the current scale. Defaults to 1
.
Test
$ npm test
© 2015 Shannon Moeller me@shannonmoeller.com
Licensed under MIT