Halftone
Screen an image or a procedural field into printed dots, lines, or four-color CMYK separations.
Overview
Halftone turns continuous tone into a print screen. The canvas is divided into rotated cells; each cell samples the source once at its center and prints a dot sized by how much ink that tone needs. Three modes cover the common looks:
- Mono prints one ink on paper, like newsprint or a risograph pass.
- Color prints each dot in the source color, keeping the image's palette with a screened texture.
- CMYK separates the source into cyan, magenta, yellow, and black screens at the classic offset angles, so the inks overlap into rosettes like a magazine page.
Without src, Halftone screens a slow procedural field, which makes it a textured background that never needs an asset.
The playground uses free Unsplash photographs by Marc Wieland and Martin Péchy.
Installation
Usage
Procedural background
import { Halftone } from "honestui/shaders"
<Halftone className="h-80 rounded-xl" cellSize={10} inkColor="#1d2433" paperColor="#f4f1ea" />Image
<Halftone
alt="Blue and orange apartment buildings against a clear sky."
className="h-80 rounded-xl"
mode="cmyk"
cellSize={6}
src="https://images.unsplash.com/photo-1553933420-77617bac448e?auto=format&fit=crop&w=1600&q=85"
/>Remote image hosts must allow cross-origin use so WebGL can read the pixels. Ink and paper accept any CSS color, including custom properties and currentColor, and follow theme changes.
Smaller cells show more detail and larger cells read as a graphic pattern. Below roughly 4 pixels the dots blur into flat tone.
Accessibility
In image mode, write alt text for the image's purpose; use an empty string when the image is decorative. The original image renders underneath until the canvas has its pixels and remains in the accessibility tree afterwards, so the content survives a missing WebGL context or a blocked image. Procedural mode is decorative and hidden from assistive technology.
The procedural field animates slowly. It stops when the user prefers reduced motion, while the element is offscreen, and while the page is hidden. Images are always still. Keep text on a separate layer and check its contrast against both the ink and the paper.