
Watercolour
Turns any image, or the layers beneath, into a watercolour painting on textured paper.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
The usage always matches the preview, layers and performance settings included. No build step or package.
Copy embed gives one block to paste into any page or site builder, no setup. For your own code: add watercolour.js, ittybitty-shader.js, runtime.js, texture.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="watercolour" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="watercolour" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { watercolour } from './watercolour.js';
const canvas = document.getElementById('watercolour');
const effect = watercolour(canvas, {
showPaper: true,
showEdges: true,
image: '/examples/still-life.webp',
wash: 0.55,
bleed: 0.5,
edges: 0.6,
granulation: 0.4,
paper: 0.5,
saturation: 1.1,
tint: '#f7f2e8',
seed: 1,
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
Washes bleed softly past their edges and settle into a few layers, pigment pools darker where each wash dries, granulation speckles the heavier washes, and pale areas are left as bare paper. It works in absorbance, as real pigment does, so it can only darken the paper. Static: it paints once per change.
- Payload
- 5.6 KB brotli for watercolour.js and ittybitty-shader.js and runtime.js and texture.js, measured at build time. See the method.
- Resolution
- Device pixel ratio capped at 2.
- Frame rate
- None. One frame per change.
- When unseen
- Stops rendering when the canvas leaves the viewport or the tab is hidden, and resumes where it left off.
- Reduced motion
- Nothing to change: it never moves.
- 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.