canvas-2d
Version:
grabs a new 2d canvas context
43 lines (28 loc) • 1.02 kB
Markdown
**deprecated in favour of [2d-context](https://www.npmjs.com/package/2d-context)**
Creates a new canvas with a 2D context, returning the context.
```js
var context = require('2d-context')()
var canvas = context.canvas
```
or
```js
var canvas = document.createElement('canvas')
var context = require('2d-context')({
canvas: canvas,
alpha: true,
width: 256,
height: 256
})
```
[](https://nodei.co/npm/2d-context/)
Creates a new canvas 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`.
MIT, see [LICENSE.md](http://github.com/mattdesl/2d-context/blob/master/LICENSE.md) for details.