// 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.defaultParameters = { shimmer: 0.08, waveSpeed1: 1.2, waveSpeed2: 0.9, waveSpeed3: 0.5, brightness: 1.0, color1: '031521', color2: '024f6d', color3: '13a4a1', color4: '67dcd0', color5: 'fcdba4', }; } 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; const paletteStops = [ { stop: 0.0, color: hexToRgb(this.getParameter('color1') || '031521') }, { stop: 0.35, color: hexToRgb(this.getParameter('color2') || '024f6d') }, { stop: 0.65, color: hexToRgb(this.getParameter('color3') || '13a4a1') }, { stop: 0.85, color: hexToRgb(this.getParameter('color4') || '67dcd0') }, { stop: 1.0, color: hexToRgb(this.getParameter('color5') || 'fcdba4') }, ]; 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(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 }, color1: { type: 'color', default: '031521' }, color2: { type: 'color', default: '024f6d' }, color3: { type: 'color', default: '13a4a1' }, color4: { type: 'color', default: '67dcd0' }, color5: { type: 'color', default: 'fcdba4' }, }, width: this.width, height: this.height, }; } } module.exports = OceanGlimmerPreset;