Dither canvas
Playground
Source Type
Sample Artwork
Custom URL
Matrix Algorithm
Variant
Install
npm install @shavin/fximport { DitherCanvas } from "@shavin/fx";Works with
React
Client component; Next.js and any React 18+ app
Remotion
Frame-exact through FxTimeProvider or time
Anatomy
import { DitherCanvas } from "@shavin/fx";
<DitherCanvas
src="/assets/hq_marshall.jpg"
algorithm="bayer8x8"
colorMode="tint"
color="brand"
scale={1.2}
className="rounded-[var(--radius-panel)]"
/>Examples
Bayer 8x8
A photo dithered with the 8x8 Bayer matrix, keeping its own colours.
Component Source
<DitherCanvas
src="/assets/hq_marshall.jpg"
algorithm="bayer8x8"
scale={1.0}
className="max-w-xs"
/>Bayer 4x4 in the brand colour
The coarser 4x4 matrix with colorMode="tint": dark areas become brand dots and light areas turn transparent.
Component Source
<DitherCanvas
src="/assets/hq_marshall.jpg"
algorithm="bayer4x4"
colorMode="tint"
color="brand"
scale={1.6}
className="max-w-xs"
/>Video
A looping video dithered frame by frame in WebGL. A .mp4 or .webm src is detected as video.
Component Source
<DitherCanvas
src="/assets/dither-sample.mp4"
algorithm="bayer8x8"
colorMode="tint"
color="brand"
scale={1.4}
autoPlay={true}
loop={true}
muted={true}
className="max-w-md rounded-[var(--radius-panel)]"
/>Props
| Prop | Type | Default | Description |
|---|---|---|---|
| src | string | { light: string; dark: string } | "/assets/hq_marshall.jpg" | Image or video URL, or a { light, dark } pair that follows the theme. Video is detected from the extension (.mp4, .webm, .ogg, .mov) or a blob: URL. |
| alt | string | "" | Accessible description of the media. |
| mediaType | "auto" | "image" | "video" | "auto" | Forces image or video handling instead of detecting it from src. |
| algorithm | "bayer8x8" | "bayer4x4" | "floyd-steinberg" | "atkinson" | "bayer8x8" | Dither matrix. Only the two Bayer matrices are implemented; "floyd-steinberg" and "atkinson" currently render as "bayer8x8". |
| colorMode | "preserve" | "tint" | "monochrome" | — | "preserve" keeps the source colours, "tint" draws dark dots in color over transparency, "monochrome" renders black and white. When unset it is "preserve", or "tint" if color is set. |
| color | FxColor: "fg" | "brand" | "muted" | string | { light: string; dark: string } | "brand" | Tint colour for colorMode="tint": a theme token, any CSS colour or var(--token), or a { light, dark } pair. The old values "default", "true", "monochrome" and "theme" are still accepted but deprecated: use colorMode. |
| scale | number | 1.0 | Pixel size multiplier. Higher values give bigger, coarser pixels. |
| threshold | number | 128 | Brightness cut-off from 0 to 255. |
| autoPlay | boolean | true | Video only: start playing on mount. |
| loop | boolean | true | Video only: loop playback. |
| muted | boolean | true | Video only: mute the audio, which browsers require for autoplay. |
| playsInline | boolean | true | Video only: play inline on mobile browsers. |
| time | number | — | Controlled time in seconds (e.g. frame / fps in Remotion); also read from FxTimeProvider. Video is sought to this time instead of playing; the render holds until the frame or image is drawn. |