228

Soliton Collision

Nonlinear self-reinforcing solitary wave packets governed by the KdV equation, colliding and emerging unchanged in shape.

Playground
60 FPS Canvas 2D
Click + Drag to interact with field
</>

Full Executable Algorithm Code

// 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
  );
}
Edit in Interactive Playground Zero Dependencies • Standalone Canvas 2D
ƒ

Mathematical Formulation

medium
Analytical Equation
ut+6uux+3ux3=0,u(x,t)=2k2sech2(k(x4k2t))\frac{\partial u}{\partial t} + 6u \frac{\partial u}{\partial x} + \frac{\partial^3 u}{\partial x^3} = 0, \quad u(x,t) = 2k^2 \operatorname{sech}^2(k(x - 4k^2 t))
Click to expand
Compact Formula
u(x, t) = 2k² * sech²(k(x - 4k² t)), total_u = u1(x, t) + u2(x, -t)

Mathematical Tags

#soliton #kdv #non-linear #hydrodynamics #waves #physics
Author: Math Art Core Target: 60 FPS

Export & Embed: Soliton Collision

4K PNG Snapshot

High-resolution single frame render

WebM Video (5s Loop)

60 FPS browser-captured stream

Standalone JS Script

Complete executable Canvas 2D algorithm

HTML Iframe Embed

<iframe src="https://art.fazleyrabbi.xyz/embed/soliton-pulse" width="500" height="500" frameborder="0" loading="lazy"></iframe>
ESC
↑↓ Navigate Select
110 Mathematical Artworks
Made by Fazley Rabbi

Support the Project

Keep mathematical creative coding alive & open source

Or via Direct Payoneer ($0 Fee)
Payoneer Customer ID: $0 Fee Direct
24076084

💡 Payoneer app: Go to Pay → Pay to recipient → Enter ID 24076084.

Thank you for supporting generative mathematical animations! ✨