54 lines
1.5 KiB
JavaScript
54 lines
1.5 KiB
JavaScript
// Rainbow preset for LEDLab
|
|
|
|
const BasePreset = require('./base-preset');
|
|
const { createFrame, wheel } = require('./frame-utils');
|
|
|
|
class RainbowPreset extends BasePreset {
|
|
constructor(width = 16, height = 16) {
|
|
super(width, height);
|
|
this.defaultParameters = {
|
|
speed: 1,
|
|
brightness: 1.0,
|
|
offset: 0,
|
|
};
|
|
}
|
|
|
|
renderFrame() {
|
|
const frame = createFrame(this.width, this.height);
|
|
const speed = this.getParameter('speed') || 1;
|
|
const brightness = this.getParameter('brightness') || 1.0;
|
|
const offset = (this.getParameter('offset') || 0) + this.frameCount * speed;
|
|
|
|
for (let i = 0; i < frame.length; i++) {
|
|
const colorIndex = (i * 256 / frame.length + offset) & 255;
|
|
const [r, g, b] = wheel(colorIndex);
|
|
|
|
// Apply brightness
|
|
const adjustedR = Math.round(r * brightness);
|
|
const adjustedG = Math.round(g * brightness);
|
|
const adjustedB = Math.round(b * brightness);
|
|
|
|
frame[i] = adjustedR.toString(16).padStart(2, '0') +
|
|
adjustedG.toString(16).padStart(2, '0') +
|
|
adjustedB.toString(16).padStart(2, '0');
|
|
}
|
|
|
|
return frame;
|
|
}
|
|
|
|
getMetadata() {
|
|
return {
|
|
name: 'Rainbow',
|
|
description: 'Classic rainbow pattern that cycles through colors',
|
|
parameters: {
|
|
speed: { type: 'range', min: 0.1, max: 5.0, step: 0.1, default: 1.0 },
|
|
brightness: { type: 'range', min: 0.1, max: 1.0, step: 0.1, default: 1.0 },
|
|
},
|
|
width: this.width,
|
|
height: this.height,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = RainbowPreset;
|