StealThis .dev

Animated Gradient Mesh BG

An organic animated gradient mesh background using Canvas 2D. Multiple color orbs drift and blend in real-time — no WebGL required.

Open in Lab
canvas vanilla-js
Targets: JS HTML

Code

Animated Gradient Mesh BG

An organic animated background built on Canvas 2D — no WebGL, no Three.js. Multiple radial gradient “orbs” drift independently using sine/cosine oscillation, blending into a fluid mesh.

How it works

Each orb has:

  • An origin point (cx, cy)
  • Amplitude and frequency for X/Y oscillation
  • A phase offset so orbs never move in sync
  • A createRadialGradient() with a vivid color at center → transparent at edge

Every frame all orbs are redrawn with globalCompositeOperation: "screen" — the additive blending creates rich color overlap:

ctx.globalCompositeOperation = "screen";
orbs.forEach(orb => {
  const x = orb.cx + Math.sin(t * orb.fx + orb.px) * orb.ax;
  const y = orb.cy + Math.cos(t * orb.fy + orb.py) * orb.ay;
  const g = ctx.createRadialGradient(x, y, 0, x, y, orb.r);
  g.addColorStop(0, orb.color);
  g.addColorStop(1, "transparent");
  ctx.fillStyle = g;
  ctx.fillRect(0, 0, W, H);
});

Performance

  • Pure Canvas 2D — runs on any device that supports <canvas>
  • will-change: transform on the canvas for GPU compositing
  • Resize observer keeps canvas pixel-perfect on window resize