
ittybitty
CRT
Plays any image, or the layers beneath, on a curved tube monitor or a worn videotape.
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 crt.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="crt" style="width: 100%; aspect-ratio: 16 / 10;"></ittybitty-shader>
<!-- Or with JavaScript, for full control: -->
<canvas id="crt" aria-hidden="true" style="width: 100%; aspect-ratio: 16 / 10; display: block"></canvas>
<script type="module">
import { crt } from './crt.js';
const canvas = document.getElementById('crt');
const effect = crt(canvas, {
showFrame: true,
showScanlines: true,
showMask: true,
showBloom: true,
showNoise: true,
image: '/examples/still-life.webp',
style: 'crt',
speed: 1,
curvature: 0.5,
scanlines: 0.6,
mask: 0.45,
bleed: 0.35,
noise: 0.3,
bloom: 0.5,
lines: 240,
// Performance
dpr: 2,
adaptive: true,
});
// Later: effect.set(…), effect.pause(), effect.resume(), effect.destroy()
</script>
Details
CRT gives a curved tube with glowing phosphor stripes, scanlines that thin in the dark and swell in the light, and a soft bloom. VHS gives colour bleeding sideways, tracking bands rolling up the picture, jittering lines and tape noise.
- Payload
- 5.8 KB brotli for crt.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
- 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.