Skip to documentation content

Halftone

Screen an image or a procedural field into printed dots, lines, or four-color CMYK separations.

halftone-demo

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

npm install honestui

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.

API Reference

PropTypeDefaultDescription
srcstring–Image to screen. Omit it to screen the procedural field.
altstring–Alternative text for the image. Required with src; use an empty string for decorative images.
modemono|color|cmyk"mono"One ink, dots in the source color, or four-color separation.
shapecircle|square|line"circle"Shape of each dot. line prints a line screen.
cellSizenumber8Dot pitch in CSS pixels.
anglenumber45Screen angle in degrees. CMYK screens are offset from it.
inkColorstring"#16181d"Ink color in mono mode. Any CSS color.
paperColorstring"#f4f1ea"Paper color behind the dots. Any CSS color.
dotScalenumber1Scales every dot. At 1 the darkest tones print solid.
contrastnumber1.1Tone contrast applied before screening.
brightnessnumber0Brightness offset from -1 to 1 applied before screening.
roughnessnumber0.15Random variation in dot size, like ink on uncoated paper.
animatedbooleantrueAnimates the procedural field. Images are always still.
speednumber0.6Speed of the procedural field.
sourceColors[string, string, string]–Three colors of the procedural field.
pausedbooleanfalseRenders one still frame.
classNamestring–Class for sizing and positioning the container.
childrenReactNode–Content layered above the effect.