// 019 - Soliton Collision (waves)
// 1:1 Original algorithm engine source
function createSolitonPulse() {
const SAMPLES = 250;
const LINES = 24;
return {
setup() {
},
render(context, timeState, params) {
const { ctx, width, height } = context;
const t = timeState.time * Number(params.speed || 1) % 10;
const amp = Number(params.amplitude || 45);
ctx.fillStyle = "#08090d";
ctx.fillRect(0, 0, width, height);
const cy = height * 0.5;
for (let l = 0; l < LINES; l++) {
const lineOffset = (l - LINES / 2) * 12;
const phaseShift = l * 0.15;
ctx.beginPath();
for (let i = 0; i <= SAMPLES; i++) {
const normX = i / SAMPLES * 20 - 10;
const renderX = i / SAMPLES * width;
const k1 = 0.8;
const pos1 = k1 * (normX - 4 * k1 * k1 * (t * 0.8 - 4) + phaseShift);
const sech1 = 1 / Math.cosh(pos1);
const u1 = 2 * k1 * k1 * sech1 * sech1;
const k2 = 0.6;
const pos2 = -k2 * (normX + 4 * k2 * k2 * (t * 0.8 - 4) - phaseShift);
const sech2 = 1 / Math.cosh(pos2);
const u2 = 2 * k2 * k2 * sech2 * sech2;
const totalWave = (u1 + u2) * amp;
const renderY = cy + lineOffset - totalWave;
if (i === 0) ctx.moveTo(renderX, renderY);
else ctx.lineTo(renderX, renderY);
}
const hue = (175 + l * 6 + timeState.time * 20) % 360;
ctx.strokeStyle = hsla(hue, 90, 65, 0.7);
ctx.lineWidth = 1.4;
ctx.stroke();
}
}
};
}
// Default parameters from content metadata
const defaultParams = [
{
"key": "amplitude",
"label": "Pulse Amplitude",
"type": "range",
"min": 15,
"max": 80,
"step": 2,
"defaultValue": 45,
"description": "Peak soliton height"
},
{
"key": "speed",
"label": "Propagation Velocity",
"type": "range",
"min": 0.3,
"max": 3,
"step": 0.1,
"defaultValue": 1,
"description": "Non-linear wave speed"
}
];
if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['soliton-pulse']) {
const inst = typeof createSolitonPulse === 'function' ? createSolitonPulse() : null;
if (inst && inst.setup) {
inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
}
window.__art_instances['soliton-pulse'] = inst;
}
const instance = window.__art_instances['soliton-pulse'];
if (instance && instance.render) {
instance.render(
{ ctx, width, height, dpr: 1, aspectRatio: width / height },
{ time, deltaTime: dt, frameCount: Math.floor(time * 60), fps: 60 },
defaultParams
);
}