@ginden/blinkstick-v2
Version:
Improved Blickstick API for Node.js
30 lines • 1.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ComplexFrame = void 0;
const tsafe_1 = require("tsafe");
/**
* Complex frame represents a single frame of animation with multiple colors and a specific duration.
* @category Animation
*/
class ComplexFrame {
constructor(colors, duration) {
this.colors = colors;
this.duration = duration | 0;
}
static fromSimpleFrame(frame, ledCount) {
const { rgb, duration } = frame;
const rgbCopy = [...rgb];
const colors = Array.from({ length: ledCount }, () => rgbCopy);
return new ComplexFrame(colors, duration | 0);
}
static createValid(colors, duration) {
(0, tsafe_1.assert)(duration >= 0, 'Duration must be a non-negative number');
for (const [index, tuple] of colors.entries()) {
(0, tsafe_1.assert)(Array.isArray(tuple) && tuple.length === 3, `Color at index ${index} must be an RGB tuple`);
(0, tsafe_1.assert)(tuple.every((color) => typeof color === 'number' && color >= 0 && color <= 255), `Color at index ${index} must be a valid RGB value (0-255)`);
}
return new ComplexFrame(colors, duration | 0);
}
}
exports.ComplexFrame = ComplexFrame;
//# sourceMappingURL=complex-frame.js.map