Koi Pond shader preview: Koi gliding through a pond from above, slipping under lily pads and darting from the pointer.
ittybitty

Koi Pond

Koi gliding through a pond from above, slipping under lily pads and darting from the pointer.

Code

The usage always matches the preview, layers and performance settings included. No build step or package.

Use as
Code view

Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add koi.js, ittybitty-shader.js, runtime.js, pointer.js next to this page. Highlighted values follow the controls.

<!-- Quickest: one element. Size it with CSS; it fills its box. -->
<script type="module" src="./ittybitty-shader.js"></script>
<ittybitty-shader effect="koi" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="koi" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>

<script type="module">
  import { koi } from './koi.js';

  const canvas = document.getElementById('koi');
  const effect = koi(canvas, {
    showWater: true,
    showShadows: true,
    showFish: true,
    showPads: true,
    showGlints: true,
    speed: 0.6,
    count: 6,
    size: 1,
    pads: 0.5,
    ripples: 0.6,
    interactive: true,
    responsiveness: 0.5,
    water: '#12302e',
    orange: '#ff6a1f',
    variation: 0.5,
    pad: '#3f7a3a',
    // Performance
    dpr: 2,
    adaptive: true,
  });

  // Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>

Details

Koi swim slow winding loops, bodies flexing as they turn, broad translucent tails and fins sweeping. Each is a real variety: kohaku, tancho, sanke, gleaming ogon or bronze chagoi. They cast soft shadows on a floor netted with caustic light and slip under floating lily pads; the pointer sends them darting away and ripples across the surface.

Payload
10.2 KB brotli for koi.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 2.
Frame rate
Display rate.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
Shows a single still frame. Controls still update it.
Layers
Up to five effects fuse into one shader and one draw call. Filters such as dithering and halftone process the layers beneath them.
Browsers
Any browser with WebGL2: Chrome and Edge 56+, Firefox 51+, Safari 15+.
Licence
MIT. Copy it, change it, ship it.