node package manager


Render an ndarray to a canvas


Renders a 2D ndarray to a canvas element.

npm install ndarray-canvas

Renders a single ndarray as a greyscale image, returning the canvas element. If a canvas element is not supplied, a new one will be created. Values in the array are expected to range between 0 and 255.

If you supply three ndarrays to the function (one representing each channel), you can get an RGB canvas back instead!

Take the following example:

var cave = require('cave-automata-2d')
  , fill = require('ndarray-fill')
  , zeros = require('zeros')
  , render = require('./')
function amplify(array) {
  return fill(array, function(x, y) {
    return array.get(x, y) * 255
function generate() {
  var array = zeros([250, 250])
  return array
var greyscale = render(null, generate())
  , rgb = render(null, generate(), generate(), generate())

And you should get back something like this: