Patterns & tiling

Repeating patterns you can color and animate: checkers, stripes, zigzags, rings, falling streaks, and tiled lattices of squares, hexagons, triangles, bricks, truchet arcs, woven threads and isometric cubes, plus the print-screen filters (halftone dots, CMYK plates and dithering). Most pattern words return a mask: a number per pixel that is 1 on the pattern and 0 off it. The lattice words also return a per-cell shade, a brightness factor around 1 that vary multiplies into a fill so every tile reads slightly different.

The lattice words share one coordinate system: cellFrame sets how many cells fit down the canvas height and how far the lattice is rotated, and gridLines, hexLines, triangleLines, truchetArcs, weaveThreads and isoCubeFaces draw inside it. The free-standing words (checkerCells, stripeBands, ringWaves, dotLattice, brickCourses) bring their own. Color a mask with strokeOver (fill where 0, stroke where 1, in a chosen color space) or hang it under one color as alpha with withAlpha; the result goes in paint:. The halftone and dither words are filters over the layer inside them and go in effect:.

import {patterns} from 'shaders/std'

Reach for it when

When you needUse
a two-color checkerboardcheckerCells colored with strokeOver
stripes or chevrons that scrollstripeBands, zigzagBands
rings rippling out from a pointringWaves
rain or streaks falling across the canvasfallingStreaks with withAlpha
a field of dots, optionally staggered or twinklingdotLattice under withAlpha
grid lines, honeycombs or triangle latticescellFrame with gridLines, hexLines, triangleLines
every tile a slightly different brightnessvary with a lattice word's shade output
a brick wallbrickCourses
a maze of joined arcstruchetArcs
a woven textileweaveThreads
tumbling 3D cubesisoCubeFaces with times, mixOf, opaque
a mapped size or thickness that should change per whole cellsampleMapsAtCellCentres on the definition's mapSampleUVs field
a halftone dot screen over the layer insidedotScreen
a four-color print with plate angles and misregistrationcmykPress with inkPlate
your own ink press inside a gather builddotScreenMask, inkTransmission
one select prop that swaps whole effect recipeschosenBy
a retro ditherpixelGrid, quantise, ditherInks
a color's alpha or RGB on its ownalphaOf, rgbOf

Example

import {defineShader, p, patterns, transformColor, transformColorSpace, transformAngle, colorSpaceOptions} from 'shaders/std'

const {cellFrame, hexLines, strokeOver, vary} = patterns

// A honeycomb: hexagon lines in a rotatable lattice, each cell's fill lightened or darkened at random.
const field = hexLines({
  frame: cellFrame({cells: p('cells'), rotation: p('rotation'), convention: 'clockwise'}),
  thickness: p('thickness'),
  softness: p('softness'),
  variation: p('variation'),
})

export const Honeycomb = defineShader({
  name: 'Honeycomb',
  props: {
    fill: {default: '#101828', transform: transformColor},
    line: {default: '#f5d90a', transform: transformColor},
    colorSpace: {default: 'linear', transform: transformColorSpace, compileTime: true, ui: {type: 'select', options: colorSpaceOptions}},
    cells: {default: 8},
    thickness: {default: 1},
    rotation: {default: 0, transform: transformAngle},
    softness: {default: 0},
    variation: {default: 0.3},
  },
  paint: strokeOver({
    fill: vary(p('fill'), field.shade),
    stroke: p('line'),
    mask: field.lines,
    space: p('colorSpace'),
  }),
})

Types

TypeWhat it is
CellFrameConventionWhich way a lattice's rows and rotation run.
GatherStageA value computed per pixel from the layer inside a gather effect, such as a dither level.
InkPlateSpecOne ink plate of a cmykPress: which channel it prints, its screen-angle prop (degrees) and its ink-color prop.
PaintSlotWhat a pattern slot accepts: a prop p('name') or another pattern value.
PatternPaintA pattern value: something you place in paint: or hand to another pattern word, yielding a color or a mask per pixel.
PixelGridThe pixel grid a dither works on, from pixelGrid: the cell size prop, the cell coordinate coord, and source, the child's color sampled once per cell.
ScatterOptionsWhat scatterPoint and scatterPoints take.
ScatteredPointOne scattered point: where it sits, the pixel's offset from it, and three random 0–1 values for its cell.

Words