Split a big canvas element into a grid of lots of little canvas elements.
JavaScript
Switch branches/tags
Nothing to show
Latest commit 69b5116 Aug 20, 2017
Permalink
Failed to load latest commit information.
demo update demo Feb 4, 2013
.gitignore first commit Feb 3, 2013
LICENSE.md first commit Feb 3, 2013
README.md deprecate Aug 20, 2017
index.js first commit Feb 3, 2013
package.json 0.0.2 Feb 4, 2013

README.md

canvas-splitter

Deprecated: this is more efficient by not creating multiple canvas contexts.

Split a big canvas element into a grid of lots of little canvas elements. Useful for spritemaps and the like.

Installation

$ npm install canvas-splitter

Usage

splitter(canvas, options)

Break up the canvas element, returning an array of the resulting canvas elements. Options include:

  • width: The width of each cell.
  • height: The height of each cell.
  • rows: The vertical number of cells to include. Optional.
  • cols: The horizontal number of cells to include. Optional.

splitter.segment(canvas, x, y, width, height)

Returns a smaller copy of the canvas.

var splitter = require('splitter')
  , lut = require('lut')

// Create a 1024x32 colour table canvas element.
var big = lut(32, 32, 32)

// Turn that table into 32 little
// colour tables, which are 32x32 each.
var little = splitter(big, {
  width: 32, height: 32, rows: 1, cols: 32
})