
Ship something
people remember.
A button that wakes up when you reach for it.
ittybitty
Gradient Map
Recolour an image, or any layer stack, through your gradient.
This browser cannot run WebGL2, so this is a still image. The code below works wherever WebGL2 is available.
Code
For your own build, add gradient-map.js, ittybitty-shader.js, runtime.js and 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="gradient-map" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="gradient-map" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { gradientMap } from './gradient-map.js';
const canvas = document.getElementById('gradient-map');
const effect = gradientMap(canvas, {
image: '/examples/gradient-map.webp',
style: 'smooth',
steps: 5,
contrast: 1.1,
brightness: 0,
reverse: false,
palette: [[0, '#1a1036'], [0.45, '#d4336f'], [0.8, '#ffb86b'], [1, '#fff6e0']],
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
The classic gradient map: lightness from shadow to highlight replaced by your gradient, smoothly or in flat posterised steps. On its own it maps an image; as a layer it recolours everything beneath it, so any effect can take any palette. It draws once per change.
- Payload
- 5.5 KB brotli for gradient-map.js, ittybitty-shader.js, runtime.js and texture.js, measured at build time.
- 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.
- Source
- gradient-map.js on GitHub, in a public repo that logs every change.