104 lines
3.9 KiB
JavaScript
104 lines
3.9 KiB
JavaScript
// Wormhole Tunnel preset for LEDLab
|
|
|
|
const BasePreset = require('./base-preset');
|
|
const { createFrame, frameToPayload, hexToRgb, samplePalette, toIndex, clamp } = require('./frame-utils');
|
|
|
|
class WormholeTunnelPreset extends BasePreset {
|
|
constructor(width = 16, height = 16) {
|
|
super(width, height);
|
|
this.timeSeconds = 0;
|
|
this.defaultParameters = {
|
|
ringDensity: 8,
|
|
ringSpeed: 1.4,
|
|
ringSharpness: 7.5,
|
|
twistIntensity: 2.2,
|
|
twistSpeed: 0.9,
|
|
coreExponent: 1.6,
|
|
brightness: 1.0,
|
|
color1: '010005',
|
|
color2: '07204f',
|
|
color3: '124aa0',
|
|
color4: '36a5ff',
|
|
color5: '99e6ff',
|
|
color6: 'f1fbff',
|
|
};
|
|
}
|
|
|
|
renderFrame() {
|
|
this.timeSeconds += 0.016; // Assume 60 FPS
|
|
|
|
const frame = createFrame(this.width, this.height);
|
|
const brightness = this.getParameter('brightness') || 1.0;
|
|
|
|
const paletteStops = [
|
|
{ stop: 0.0, color: hexToRgb(this.getParameter('color1') || '010005') },
|
|
{ stop: 0.2, color: hexToRgb(this.getParameter('color2') || '07204f') },
|
|
{ stop: 0.45, color: hexToRgb(this.getParameter('color3') || '124aa0') },
|
|
{ stop: 0.7, color: hexToRgb(this.getParameter('color4') || '36a5ff') },
|
|
{ stop: 0.87, color: hexToRgb(this.getParameter('color5') || '99e6ff') },
|
|
{ stop: 1.0, color: hexToRgb(this.getParameter('color6') || 'f1fbff') },
|
|
];
|
|
|
|
const cx = (this.width - 1) / 2;
|
|
const cy = (this.height - 1) / 2;
|
|
const radiusNorm = Math.hypot(cx, cy) || 1;
|
|
|
|
for (let row = 0; row < this.height; ++row) {
|
|
for (let col = 0; col < this.width; ++col) {
|
|
const dx = col - cx;
|
|
const dy = row - cy;
|
|
const radius = Math.hypot(dx, dy) / radiusNorm;
|
|
const angle = Math.atan2(dy, dx);
|
|
|
|
const radialPhase = radius * (this.getParameter('ringDensity') || 8) - this.timeSeconds * (this.getParameter('ringSpeed') || 1.4);
|
|
const ring = Math.exp(-Math.pow(Math.sin(radialPhase * Math.PI), 2) * (this.getParameter('ringSharpness') || 7.5));
|
|
|
|
const twist = Math.sin(angle * (this.getParameter('twistIntensity') || 2.2) + this.timeSeconds * (this.getParameter('twistSpeed') || 0.9)) * 0.35 + 0.65;
|
|
const depth = Math.pow(clamp(1 - radius, 0, 1), this.getParameter('coreExponent') || 1.6);
|
|
|
|
const value = clamp(ring * 0.6 + depth * 0.3 + twist * 0.1, 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: 'Wormhole Tunnel',
|
|
description: 'Hypnotic tunnel effect with rotating rings',
|
|
parameters: {
|
|
ringDensity: { type: 'range', min: 4, max: 12, step: 1, default: 8 },
|
|
ringSpeed: { type: 'range', min: 0.5, max: 2.5, step: 0.1, default: 1.4 },
|
|
ringSharpness: { type: 'range', min: 3, max: 12, step: 0.5, default: 7.5 },
|
|
twistIntensity: { type: 'range', min: 1.0, max: 4.0, step: 0.2, default: 2.2 },
|
|
twistSpeed: { type: 'range', min: 0.3, max: 1.5, step: 0.1, default: 0.9 },
|
|
coreExponent: { type: 'range', min: 1.0, max: 2.5, step: 0.1, default: 1.6 },
|
|
brightness: { type: 'range', min: 0.3, max: 1.0, step: 0.1, default: 1.0 },
|
|
color1: { type: 'color', default: '010005' },
|
|
color2: { type: 'color', default: '07204f' },
|
|
color3: { type: 'color', default: '124aa0' },
|
|
color4: { type: 'color', default: '36a5ff' },
|
|
color5: { type: 'color', default: '99e6ff' },
|
|
color6: { type: 'color', default: 'f1fbff' },
|
|
},
|
|
width: this.width,
|
|
height: this.height,
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = WormholeTunnelPreset;
|