438

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


import type { ArtRenderer, ParameterState, RenderContext, TimeState } from '../../types/engine';
import { hsla } from '../common/color';

// Korteweg-de Vries (KdV) Soliton wave packet collision: u(x,t) = 2*k^2 * sech^2(k*(x - 4*k^2*t))
export function createSolitonPulse(): ArtRenderer {
  const SAMPLES = 250;
  const LINES = 24;

  return {
    setup() {},

    render(context: RenderContext, timeState: TimeState, params: ParameterState) {
      const { ctx, width, height } = context;
      const t = (timeState.time * Number(params.speed || 1.0)) % 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; // -10 to +10
          const renderX = (i / SAMPLES) * width;

          // Soliton 1 (traveling right)
          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;

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

Mathematical Formulation

medium
Analytical Equation
∂u∂t+6u∂u∂x+∂3u∂x3=0,u(x,t)=2k2sech⁡2(k(x−4k2t))\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
113 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! ✨