Ink shader preview: Ink pouring from the pointer and curling away like smoke in water.
ittybitty

Ink

Ink pouring from the pointer and curling away like smoke in water.

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 ink.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="ink" style="width: 100%; height: 480px;"></ittybitty-shader>

<!-- Or with JavaScript, for full control: -->
<canvas id="ink" aria-hidden="true" style="width: 100%; height: 480px; display: block"></canvas>

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

  const canvas = document.getElementById('ink');
  const effect = ink(canvas, {
    showBackground: true,
    idle: true,
    speed: 0.6,
    style: 'ink',
    size: 0.07,
    spread: 1.2,
    fade: 0.8,
    curl: 0.7,
    palette: [[0, '#ffe3a3'], [0.35, '#ff5c8a'], [0.7, '#6a3bff'], [1, '#1b1840']],
    background: '#0b0b12',
    responsiveness: 0.5,
    // Performance
    dpr: 1,
    adaptive: true,
  });

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

Details

The last 24 pointer positions become drops of ink that bloom, curl and fade on their own, coloured from fresh to old by your palette. Without a pointer an invisible hand draws slow loops. One pass and no fluid solver: it looks like fluid and costs about as much as a gradient.

Payload
6.1 KB brotli for ink.js and ittybitty-shader.js and runtime.js and pointer.js, measured at build time. See the method.
Resolution
Device pixel ratio capped at 1; ink is soft.
Frame rate
Display rate while ink is on screen.
When unseen
Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
Reduced motion
The idle hand stays still; ink still follows the pointer.
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.