UNPKG

xled-js

Version:

Library to control Twinkly LED lights

44 lines (43 loc) 936 B
/** * A frame of LEDs, used when you wish to set color pixel by pixel * * @export * @class Frame * @typedef {Frame} */ export class Frame { /** * Creates an instance of Frame. * * @constructor * @param {Led[]} leds Array of Led, of same length as nleds */ constructor(leds) { this.leds = leds; } /** * Output the frame as a Uint8Array of bytes * * @returns {Uint8Array} */ toOctet() { let bytes = this.leds.map((led) => { return led.toOctet(); }); let output = new Uint8Array(this.leds.length * 3); let offset = 0; bytes.forEach((item) => { output.set(item, offset); offset += item.length; }); return output; } /** * Get the number of LEDs in this frame * * @returns {number} */ getNLeds() { return this.leds.length; } }