feat: ledlab
This commit is contained in:
81
presets/nebula-drift-preset.js
Normal file
81
presets/nebula-drift-preset.js
Normal file
@@ -0,0 +1,81 @@
|
||||
// Nebula Drift preset for LEDLab
|
||||
|
||||
const BasePreset = require('./base-preset');
|
||||
const { createFrame, frameToPayload, hexToRgb, samplePalette, toIndex, clamp } = require('./frame-utils');
|
||||
|
||||
class NebulaDriftPreset extends BasePreset {
|
||||
constructor(width = 16, height = 16) {
|
||||
super(width, height);
|
||||
this.timeSeconds = 0;
|
||||
this.paletteStops = [
|
||||
{ stop: 0.0, color: hexToRgb('100406') },
|
||||
{ stop: 0.25, color: hexToRgb('2e0f1f') },
|
||||
{ stop: 0.5, color: hexToRgb('6a1731') },
|
||||
{ stop: 0.7, color: hexToRgb('b63b32') },
|
||||
{ stop: 0.85, color: hexToRgb('f48b2a') },
|
||||
{ stop: 1.0, color: hexToRgb('ffe9b0') },
|
||||
];
|
||||
this.defaultParameters = {
|
||||
primarySpeed: 0.15,
|
||||
secondarySpeed: 0.32,
|
||||
waveScale: 0.75,
|
||||
brightness: 1.0,
|
||||
};
|
||||
}
|
||||
|
||||
layeredWave(u, v, speed, offset) {
|
||||
return Math.sin((u * 3 + v * 2) * Math.PI * this.getParameter('waveScale') + this.timeSeconds * speed + offset);
|
||||
}
|
||||
|
||||
renderFrame() {
|
||||
this.timeSeconds += 0.016; // Assume 60 FPS
|
||||
|
||||
const frame = createFrame(this.width, this.height);
|
||||
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 primary = this.layeredWave(u, v, this.getParameter('primarySpeed') || 0.15, 0);
|
||||
const secondary = this.layeredWave(v, u, this.getParameter('secondarySpeed') || 0.32, Math.PI / 4);
|
||||
const tertiary = Math.sin((u + v) * Math.PI * 1.5 + this.timeSeconds * 0.18);
|
||||
|
||||
const combined = 0.45 * primary + 0.35 * secondary + 0.2 * tertiary;
|
||||
const envelope = Math.sin((u * v) * Math.PI * 2 + this.timeSeconds * 0.1) * 0.25 + 0.75;
|
||||
const value = clamp((combined * 0.5 + 0.5) * envelope, 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: 'Nebula Drift',
|
||||
description: 'Organic drifting nebula with layered wave patterns',
|
||||
parameters: {
|
||||
primarySpeed: { type: 'range', min: 0.05, max: 0.3, step: 0.05, default: 0.15 },
|
||||
secondarySpeed: { type: 'range', min: 0.2, max: 0.5, step: 0.02, default: 0.32 },
|
||||
waveScale: { type: 'range', min: 0.5, max: 1.0, step: 0.05, default: 0.75 },
|
||||
brightness: { type: 'range', min: 0.3, max: 1.0, step: 0.1, default: 1.0 },
|
||||
},
|
||||
width: this.width,
|
||||
height: this.height,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = NebulaDriftPreset;
|
||||
Reference in New Issue
Block a user