228

Viscous Gyre

Planetary boundary layer ocean circulation driven by non-linear wind stress curl, modeled via the Stommel double-gyre stream function.

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

Full Executable Algorithm Code

// 008 - Viscous Gyre (fluid)
// 1:1 Original algorithm engine source
function createViscousGyre() {
  const MAX_PARTICLES = 1600;
  const px = new Float32Array(MAX_PARTICLES);
  const py = new Float32Array(MAX_PARTICLES);
  return {
    setup() {
      for (let i = 0; i < MAX_PARTICLES; i++) {
        px[i] = Math.random();
        py[i] = Math.random();
      }
    },
    render(context, timeState, params) {
      const { ctx, width, height } = context;
      const count = Math.min(MAX_PARTICLES, Number(params.particleCount || 1200));
      const speed = Number(params.speed || 5e-3);
      const t = timeState.time * 0.5;
      ctx.fillStyle = "rgba(8, 9, 13, 0.15)";
      ctx.fillRect(0, 0, width, height);
      for (let i = 0; i < count; i++) {
        const x = px[i];
        const y = py[i];
        const u = 2 * Math.PI * Math.sin(Math.PI * x) * Math.cos(2 * Math.PI * y + Math.sin(t) * 0.4);
        const v = -Math.PI * Math.cos(Math.PI * x) * Math.sin(2 * Math.PI * y + Math.sin(t) * 0.4);
        const prevPx = px[i] * width;
        const prevPy = py[i] * height;
        px[i] += u * speed;
        py[i] += v * speed;
        if (px[i] < 0 || px[i] > 1 || py[i] < 0 || py[i] > 1) {
          px[i] = Math.random();
          py[i] = Math.random();
          continue;
        }
        const currPx = px[i] * width;
        const currPy = py[i] * height;
        const velMag = Math.sqrt(u * u + v * v);
        const hue = (160 + velMag * 15 + t * 20) % 360;
        ctx.strokeStyle = hsla(hue, 90, 60, Math.min(0.9, velMag * 0.15 + 0.3));
        ctx.lineWidth = 1.2;
        ctx.beginPath();
        ctx.moveTo(prevPx, prevPy);
        ctx.lineTo(currPx, currPy);
        ctx.stroke();
      }
    }
  };
}

// Default parameters from content metadata
const defaultParams = [
  {
    "key": "particleCount",
    "label": "Current Tracers",
    "type": "range",
    "min": 400,
    "max": 1600,
    "step": 100,
    "defaultValue": 1200,
    "description": "Particle count"
  },
  {
    "key": "speed",
    "label": "Circulation Velocity",
    "type": "range",
    "min": 0.001,
    "max": 0.015,
    "step": 0.001,
    "defaultValue": 0.005,
    "description": "Advection timestep"
  }
];

if (!window.__art_instances) window.__art_instances = {};
if (!window.__art_instances['viscous-gyre']) {
  const inst = typeof createViscousGyre === 'function' ? createViscousGyre() : null;
  if (inst && inst.setup) {
    inst.setup({ ctx, width, height, dpr: 1, aspectRatio: width / height }, defaultParams);
  }
  window.__art_instances['viscous-gyre'] = inst;
}

const instance = window.__art_instances['viscous-gyre'];
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
ψ(x,y)=τ0πρHβsin(πx)sin(2πy),u=ψy,v=ψx\psi(x, y) = -\frac{\tau_0}{\pi \rho H \beta} \sin(\pi x) \sin(2\pi y), \quad u = -\frac{\partial \psi}{\partial y}, \quad v = \frac{\partial \psi}{\partial x}
Click to expand
Compact Formula
u = 2π sin(πx) cos(2πy), v = -π cos(πx) sin(2πy)

Mathematical Tags

#oceanography #gyre #stream-function #fluid #geophysics
Author: Math Art Core Target: 60 FPS

Export & Embed: Viscous Gyre

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/viscous-gyre" 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! ✨