pxt-neoanim/README.md

79 строки
1.8 KiB
Markdown
Исходник Постоянная ссылка Обычный вид История

2017-05-18 19:19:35 +03:00
# neoanim
A neopixel animation based on bitmaps [![Build Status](https://travis-ci.org/Microsoft/pxt-neoanim.svg?branch=master)](https://travis-ci.org/Microsoft/pxt-neoanim)
2017-05-18 19:19:35 +03:00
2017-05-18 22:26:27 +03:00
# Animation Sheet
Creates an animation from a pre-rendered set of frames
```sig
2018-01-04 08:48:18 +03:00
light.animationSheet(null)
2017-05-18 22:26:27 +03:00
```
## Parameters
* ``buffer``, the buffer containing the data (more below)
2017-05-20 08:15:08 +03:00
## Animation editor
2017-09-29 19:51:01 +03:00
From the https://makecode.adafruit.com editor,
* click on **Add Package**
2018-01-04 08:48:18 +03:00
* add **neoanim**
2017-09-29 19:51:01 +03:00
* go to the **Lights** category and click on **Animation Editor**
2017-05-20 08:15:08 +03:00
2017-05-18 22:26:27 +03:00
## Buffer format
The bitmap format should be specified as follows. All values are little endian.
2017-05-18 22:54:32 +03:00
* magic number ``0x2e0a2188``, 4 bytes
2017-05-18 22:26:27 +03:00
* 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
2018-01-04 08:47:13 +03:00
const strip = light.createStrip();
2017-05-18 22:26:27 +03:00
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;
}
}
2018-01-04 08:47:13 +03:00
let anim = light.animationSheet(sheet);
2017-05-18 22:26:27 +03:00
loops.forever(() => {
strip.showAnimation(anim, 10000);
})
```
2017-05-18 19:19:35 +03:00
## License
MIT
## Supported targets
2017-05-20 08:15:08 +03:00
* for PXT/adafruit
2017-05-20 08:17:28 +03:00
* for PXT/codal
2017-05-18 19:19:35 +03:00
(The metadata above is needed for package search.)