feat: ledlab
This commit is contained in:
79
presets/ocean-glimmer-preset.js
Normal file
79
presets/ocean-glimmer-preset.js
Normal file
@@ -0,0 +1,79 @@
|
||||
// Ocean Glimmer preset for LEDLab
|
||||
|
||||
const BasePreset = require('./base-preset');
|
||||
const { createFrame, frameToPayload, hexToRgb, samplePalette, toIndex, clamp } = require('./frame-utils');
|
||||
|
||||
class OceanGlimmerPreset extends BasePreset {
|
||||
constructor(width = 16, height = 16) {
|
||||
super(width, height);
|
||||
this.timeSeconds = 0;
|
||||
this.paletteStops = [
|
||||
{ stop: 0.0, color: hexToRgb('031521') },
|
||||
{ stop: 0.35, color: hexToRgb('024f6d') },
|
||||
{ stop: 0.65, color: hexToRgb('13a4a1') },
|
||||
{ stop: 0.85, color: hexToRgb('67dcd0') },
|
||||
{ stop: 1.0, color: hexToRgb('fcdba4') },
|
||||
];
|
||||
this.defaultParameters = {
|
||||
shimmer: 0.08,
|
||||
waveSpeed1: 1.2,
|
||||
waveSpeed2: 0.9,
|
||||
waveSpeed3: 0.5,
|
||||
brightness: 1.0,
|
||||
};
|
||||
}
|
||||
|
||||
renderFrame() {
|
||||
this.timeSeconds += 0.016; // Assume 60 FPS
|
||||
|
||||
const frame = createFrame(this.width, this.height);
|
||||
const shimmer = this.getParameter('shimmer') || 0.08;
|
||||
const brightness = this.getParameter('brightness') || 1.0;
|
||||
|
||||
for (let row = 0; row < this.height; ++row) {
|
||||
const v = row / Math.max(1, this.height - 1);
|
||||
for (let col = 0; col < this.width; ++col) {
|
||||
const u = col / Math.max(1, this.width - 1);
|
||||
const base =
|
||||
0.33 +
|
||||
0.26 * Math.sin(u * Math.PI * 2 + this.timeSeconds * (this.getParameter('waveSpeed1') || 1.2)) +
|
||||
0.26 * Math.sin(v * Math.PI * 2 - this.timeSeconds * (this.getParameter('waveSpeed2') || 0.9)) +
|
||||
0.26 * Math.sin((u + v) * Math.PI * 2 + this.timeSeconds * (this.getParameter('waveSpeed3') || 0.5));
|
||||
const noise = (Math.random() - 0.5) * shimmer;
|
||||
const value = clamp(base + noise, 0, 1);
|
||||
|
||||
let color = samplePalette(this.paletteStops, value);
|
||||
|
||||
// Apply brightness
|
||||
if (brightness < 1.0) {
|
||||
const rgb = hexToRgb(color);
|
||||
color = Math.round(rgb.r * brightness).toString(16).padStart(2, '0') +
|
||||
Math.round(rgb.g * brightness).toString(16).padStart(2, '0') +
|
||||
Math.round(rgb.b * brightness).toString(16).padStart(2, '0');
|
||||
}
|
||||
|
||||
frame[toIndex(col, row, this.width)] = color;
|
||||
}
|
||||
}
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
getMetadata() {
|
||||
return {
|
||||
name: 'Ocean Glimmer',
|
||||
description: 'Ocean-like waves with shimmer effects',
|
||||
parameters: {
|
||||
shimmer: { type: 'range', min: 0.02, max: 0.15, step: 0.01, default: 0.08 },
|
||||
waveSpeed1: { type: 'range', min: 0.5, max: 2.0, step: 0.1, default: 1.2 },
|
||||
waveSpeed2: { type: 'range', min: 0.5, max: 2.0, step: 0.1, default: 0.9 },
|
||||
waveSpeed3: { type: 'range', min: 0.2, max: 1.0, step: 0.1, default: 0.5 },
|
||||
brightness: { type: 'range', min: 0.3, max: 1.0, step: 0.1, default: 1.0 },
|
||||
},
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OceanGlimmerPreset;
|
||||
Reference in New Issue
Block a user