Skip to content

Instantly share code, notes, and snippets.

@mikolalysenko
Created February 8, 2016 22:16
Show Gist options
  • Save mikolalysenko/9c732f07628863b529f1 to your computer and use it in GitHub Desktop.
Save mikolalysenko/9c732f07628863b529f1 to your computer and use it in GitHub Desktop.
var ndarray = require('ndarray')
//Context is a canvas 2d context
var imageData = context.createImageData(WIDTH, HEIGHT)
//Wrap pixels in an ndarray with shape [width x height x 4 (rgba)]
var ndpixels = ndarray(imageData.data, [WIDTH, HEIGHT, 4], [4, 4 * WIDTH, 1], 0)
//Now you can edit pixels as an ndarray!
// ...
//When done, you blit back using the original image
context.putImageData(imageData)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment