2017-05-18 19:19:35 +03:00
|
|
|
# neoanim
|
|
|
|
|
|
|
|
A neopixel animation based on bitmaps
|
|
|
|
|
2017-05-18 22:26:27 +03:00
|
|
|
# Animation Sheet
|
|
|
|
|
|
|
|
Creates an animation from a pre-rendered set of frames
|
|
|
|
|
|
|
|
```sig
|
|
|
|
light.animationSheet(null, 50)
|
|
|
|
```
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
|
|
|
|
* ``buffer``, the buffer containing the data (more below)
|
|
|
|
* ``interval``, the time in milliseconds between each frame
|
|
|
|
|
|
|
|
## Buffer format
|
|
|
|
|
|
|
|
The bitmap format should be specified as follows. All values are little endian.
|
|
|
|
|
|
|
|
* magic number ``0x2e0a21``, 4 bytes
|
|
|
|
* palette size, 1 byte (``npalette``)
|
|
|
|
* reserved padding, 1 byte
|
|
|
|
* palette, ``npalette`` x 24bit RGB colors
|
|
|
|
* frames, ``nleds`` x number of frames. A contiguous sequence of palette color indices.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
|
|
|
### Generating your own animation
|
|
|
|
|
|
|
|
The following sample generates a buffer and uses it to create the animation.
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
const strip = light.pixels;
|
|
|
|
const nleds = strip.length();
|
|
|
|
const ncolors = 3;
|
|
|
|
const nframes = 10;
|
|
|
|
const sheet = pins.createBuffer(6 + ncolors * 3 + nleds * nframes);
|
|
|
|
const palette = sheet.slice(6, ncolors * 3);
|
|
|
|
const frames = sheet.slice(6 + palette.length);
|
|
|
|
|
|
|
|
// magic number
|
|
|
|
sheet.setNumber(0, NumberFormat.UInt32LE, 0x2e0a21);
|
|
|
|
// palette
|
|
|
|
sheet[4] = ncolors;
|
|
|
|
palette[0] = 0xff; // red
|
|
|
|
palette[4] = 0xff; // green
|
|
|
|
palette[8] = 0xff; // blue
|
|
|
|
// filing up colors
|
|
|
|
let k = 0;
|
|
|
|
for (let i = 0; i < nleds; ++i) {
|
|
|
|
for (let j = 0; j < nframes; ++j) {
|
|
|
|
frames[k++] = i + j % ncolors;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let anim = light.animationSheet(sheet, 50);
|
|
|
|
|
|
|
|
loops.forever(() => {
|
|
|
|
strip.showAnimation(anim, 10000);
|
|
|
|
})
|
|
|
|
```
|
|
|
|
|
2017-05-18 19:19:35 +03:00
|
|
|
## License
|
|
|
|
|
|
|
|
MIT
|
|
|
|
|
|
|
|
## Supported targets
|
|
|
|
|
2017-05-18 19:19:54 +03:00
|
|
|
* for PXT/ adafruit
|
2017-05-18 19:19:35 +03:00
|
|
|
(The metadata above is needed for package search.)
|