# rpi-ws281x-canvas

> (raspberry-pi *only*) library to control a grid of ws2812-leds using a canvas

Latest version **0.1.0** (published 2015-03-10) · MIT license · 0 weekly downloads

## Install

```sh
npm install rpi-ws281x-canvas
pnpm add rpi-ws281x-canvas
yarn add rpi-ws281x-canvas
bun add rpi-ws281x-canvas
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2015-03-10 |
| First published | 2015-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.33 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Martin Schuhfuss |
| Maintainers | usefulthink |
| Keywords | raspberry-pi, ws281x, ws2812, ws2811, led, canvas, hardware |

## Links

- npm: https://www.npmjs.com/package/rpi-ws281x-canvas
- Repository: https://github.com/raspberry-node/node-rpi-ws281x-canvas
- Issues: https://github.com/raspberry-node/node-rpi-ws281x-canvas/issues
- npm.io page: https://npm.io/package/rpi-ws281x-canvas

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2015-03-10

## README

# control ws281x-LEDs using a html5-canvas in node.js

this package allows you to control a grid of WS281x-LEDs (like the Adafruit Neopixel) using a canvas-element in node.js. 
This package provides a small wrapper around the [`node-canvas`][]-module which mainly handles the format-conversion from canvas pixel-data to the Uint32-format required by the [`rpi-ws281x-native`][]-module.

## Setup

install via npm:

    npm install rpi-ws281x-canvas
 
or from source:

    git clone https://github.com/raspberry-node/node-rpi-ws281x-canvas.git
    cd node-rpi-ws281x-canvas
    npm install


## Usage

The module exports a `create(width, height)`-function that will return an instance of a `Canvas`-element.

    var ws281xCanvas = require('rpi-ws281x-canvas'),
        canvas = ws281xCanvas.create(10,10);

The returned is an instance of a HTML5-Canvas implementation ([`node-canvas`][]). 

The only additional method - `toUint32Array()` - handles the conversion of canvas pixel-data into the data-format used by the [`rpi-ws281x-native`][]-module (unsigned 32-bit integer per pixel, format: `0x00rrggbb`). For conversion of alpha-values, a black background is assumed.

In Addition to that there are two classes, `Image` and `Font`, that are made available as additional exports of the module.

### Example

This will draw a blue rectangle on the LED-Grid.

    var ws281x = require('rpi-ws281x-native'),
        canvas = require('rpi-ws281x-canvas').create(10,10),
        ctx = canvas.getContext('2d');

    ws281x.init(100);

    ctx.fillStyle = 'blue';
    ctx.fillRect(2, 2, 8, 8);
    
    ws281x.render(canvas.toUint32Array());


## Testing

a simple test-script is provided in `examples/sprite-animation.js`, it is intended to run with a 10x10 matrix, so you might need to adjust the values to match your setup.

[`node-canvas`]: https://github.com/Automattic/node-canvas
[`rpi-ws281x-native`]: https://github.com/raspberry-node/node-rpi-ws281x-native

---
_Source: https://npm.io/package/rpi-ws281x-canvas · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
