Skip to content
kerfjsGitHub

DitherGlyph

A word or logo woven out of a moving dithered field.

SourcePackage @kerf-js/veneerTry it

Preview

tsx
import { DitherGlyph } from '@kerf-js/veneer'export function Word() {  return (  <DitherGlyph    text="kerf"    ratio="4 / 1"  />  )}

Installation

npm install @kerf-js/veneer

Try it

Change the controls: the preview and its code update together. The address keeps what you set, so you can link to it.

Live preview
Controls
Kind
Ramp
Cell4
Codeupdates as you change the controls
import { DitherGlyph } from '@kerf-js/veneer'<DitherGlyph text="kerf" />

Usage

tsx
import { DitherGlyph } from '@kerf-js/veneer'<DitherGlyph  text="kerf"  ratio="4 / 1"/>

Your own drawing

draw paints the shape in cells.

tsx
import { DitherGlyph } from '@kerf-js/veneer'export function Drawn() {  return (  <DitherGlyph    draw={drawDiamond}    label="A diamond"    ratio="3 / 1"    ramp="highlight"  />  )}const drawDiamond = (  ctx: CanvasRenderingContext2D,  cols: number,  rows: number,) => {  const size = rows * 0.42  ctx.beginPath()  ctx.moveTo(cols / 2, rows / 2 - size)  ctx.lineTo(cols / 2 + size, rows / 2)  ctx.lineTo(cols / 2, rows / 2 + size)  ctx.lineTo(cols / 2 - size, rows / 2)  ctx.fill()}

Reveal

reveal draws the shape on over that many seconds.

tsx
import { DitherGlyph } from '@kerf-js/veneer'export function Reveal() {  return (  <DitherGlyph    text="Shipped"    reveal={1.6}    ramp="positive"    ratio="4 / 1"  />  )}

When to use

Use it for

  • A big brand moment: a wordmark or a logo

Reach for something else

Accessibility

  • A text glyph is real text. Give a path or draw glyph a label.

API Reference

PropTypeDefaultDescription
textstring—The word to set. It stays in the page as real text for readers and for search.
pathstring—An SVG path, for a logo.
box[width: number, height: number]—The size of the box the path was drawn in.
strokenumber—Line width, for a path made of lines.
draw((ctx: CanvasRenderingContext2D, cols: number, rows: number) => void)—Paints the shape on a canvas, in cells.
labelstring—Names a path or draw glyph.
fontstring—The font for text.
weightstring | number—The font weight for text.
fitnumber—The share of the box the shape fills, 0 to 1.
ratiostring | number—Width to height.
pointerPointerMode | PointerMode[]—How the field answers the pointer: ripple, pull or shockwave, or several.
speednumber—Multiplies the tier's speed. 0 holds one frame.
fadeFade—Dissolves the field toward a side, so type can sit on clean ground, or into the page on every edge.
kindFieldName | Field'flow'A named field, or your own function of (x, y, t).
smoothbooleanfalseYour own kind is smooth: evaluate it on a sparse lattice and interpolate, as the named fields do.
rampRamp—The inks: a tone such as accent, or your own list of colours.
sparkRamp—Inks a disturbed cell takes instead, so a push shows in a second colour.
patternPattern—The ordered-dither tile: bayer2, bayer4, bayer8, blue noise or halftone.
cellnumber4CSS pixels per cell.
inksnumber—How many inks of a tone ramp to use. Default: the tier's.
gainnumber—Tone gain, around 1. Default: the tier's.
seednumber—Where a held frame sits in the field's time, in seconds.
spreadnumber—How much of the step between inks the pattern may cross, 0–1.
revealnumber—Seconds a mask takes to draw itself on, left to right, with a flash where it lands. Needs motion.
fpsnumber—Caps the frame rate while it moves.

Parts

Every element carries a stable name, so you can style it from your own CSS: [data-scope="dither-glyph"] [data-part="glyph-text"]

glyph-text

RelatedDither fieldDither