Files
spore-ledlab/presets/fade-green-blue-preset.js
2025-10-11 17:46:32 +02:00

52 lines
1.5 KiB
JavaScript

// Fade Green Blue preset for LEDLab
const BasePreset = require('./base-preset');
const { createFrame, frameToPayload } = require('./frame-utils');
class FadeGreenBluePreset extends BasePreset {
constructor(width = 16, height = 16) {
super(width, height);
this.tick = 0;
this.defaultParameters = {
speed: 0.5, // cycles per second
brightness: 1.0,
};
}
renderFrame() {
const frame = createFrame(this.width, this.height);
const timeSeconds = (this.tick * 0.016); // Assume 60 FPS
const phase = timeSeconds * this.getParameter('speed') * Math.PI * 2;
const blend = (Math.sin(phase) + 1) * 0.5; // 0..1
const brightness = this.getParameter('brightness') || 1.0;
const green = Math.round(255 * (1 - blend) * brightness);
const blue = Math.round(255 * blend * brightness);
const gHex = green.toString(16).padStart(2, '0');
const bHex = blue.toString(16).padStart(2, '0');
for (let i = 0; i < frame.length; i++) {
frame[i] = '00' + gHex + bHex;
}
this.tick++;
return frame;
}
getMetadata() {
return {
name: 'Fade Green Blue',
description: 'Smooth fade between green and blue colors',
parameters: {
speed: { type: 'range', min: 0.1, max: 2.0, step: 0.1, default: 0.5 },
brightness: { type: 'range', min: 0.1, max: 1.0, step: 0.1, default: 1.0 },
},
width: this.width,
height: this.height,
};
}
}
module.exports = FadeGreenBluePreset;