Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hughsk/ndarray-canvas
Render a 2D ndarray to a canvas element.
https://github.com/hughsk/ndarray-canvas
Last synced: 12 days ago
JSON representation
Render a 2D ndarray to a canvas element.
- Host: GitHub
- URL: https://github.com/hughsk/ndarray-canvas
- Owner: hughsk
- License: other
- Created: 2013-07-03T23:11:47.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2013-07-03T23:12:11.000Z (over 11 years ago)
- Last Synced: 2024-10-17T16:38:57.070Z (22 days ago)
- Language: JavaScript
- Size: 203 KB
- Stars: 7
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ndarray-canvas #
Renders a 2D [ndarray](http://github.com/mikolalysenko/ndarray) to a canvas
element.## Installation ##
``` bash
npm install ndarray-canvas
```## Usage ##
### `require('ndarray-canvas')(canvas, ndarray)` ###
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.### `require('ndarray-canvas')(canvas, red, green, blue)` ###
If you supply three ndarrays to the function (one representing each channel),
you can get an RGB canvas back instead!Take the following example:
``` javascript
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])
cave(array)(20)
amplify(array)
return array
}var greyscale = render(null, generate())
, rgb = render(null, generate(), generate(), generate())document.body.appendChild(greyscale)
document.body.appendChild(rgb)
```And you should get back something like this:
[![example](https://raw.github.com/hughsk/ndarray-canvas/master/screenshot.png)](http://github.com/hughsk/ndarray-canvas/blob/master/demo.js)