
Ship something
people remember.
A button that wakes up when you reach for it.
Afterimage
Turns a photo into a long-exposure dream: smeared, ghosted, cooled, burning and grainy.
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 afterimage.js, ittybitty-shader.js, runtime.js, pointer.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="afterimage" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="afterimage" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { afterimage } from './afterimage.js';
const canvas = document.getElementById('afterimage');
const effect = afterimage(canvas, {
showGrain: true,
showFringe: true,
showLeak: false,
image: '/examples/night-city.webp',
mode: 'pan',
smear: 0.6,
angle: 6,
softness: 0.55,
smudge: 0.5,
ghost: 0.45,
glow: 0.7,
heat: 1,
grain: 0.6,
fringe: 0.5,
leak: 0.6,
fade: 0.55,
speed: 0.4,
palette: [[0, '#1b1a50'], [0.36, '#2e4fa6'], [0.7, '#4f9ac6'], [1, '#c2e8de']],
hot: '#ff4a26',
interactive: true,
// Performance
dpr: 1,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
The frame is dragged along a pan, a handheld shake, a zoom or a swirl, lights trailing furthest, then smudged and doubled into a second exposure. Everything is washed into your cool tones while warm lights burn toward the hot colour, a halo spills around anything bright, edges split into colour, the corners fall into shadow and moving film grain covers the lot. Silhouettes survive as soft shapes, so people and cars still read. The pointer drags the picture where it passes.
- Payload
- 9.2 KB brotli for afterimage.js, ittybitty-shader.js, runtime.js, pointer.js and texture.js, measured at build time.
- Resolution
- Pixel ratio 1: it is all blur and grain.
- 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.
- Source
- afterimage.js on GitHub, in a public repo that logs every change.