---
title: "Patterns & tiling"
description: "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)."
group: "paint"
groupTitle: "Painting"
categoryId: "patterns"
categorySlug: "patterns"
wordCount: 34
curated: true
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/paint/patterns.ts"
editUrl: "https://github.com/shader-effects-inc/shaders/edit/main/packages/core/docs/std/patterns.md"
---

# 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`](/docs/primitives/patterns/vary) multiplies into a fill so every tile reads slightly different.

The lattice words share one coordinate system: [`cellFrame`](/docs/primitives/patterns/cellframe) sets how many cells fit down the
canvas height and how far the lattice is rotated, and [`gridLines`](/docs/primitives/patterns/gridlines), [`hexLines`](/docs/primitives/patterns/hexlines),
[`triangleLines`](/docs/primitives/patterns/trianglelines), [`truchetArcs`](/docs/primitives/patterns/truchetarcs), [`weaveThreads`](/docs/primitives/patterns/weavethreads) and [`isoCubeFaces`](/docs/primitives/patterns/isocubefaces) draw inside it. The
free-standing words ([`checkerCells`](/docs/primitives/patterns/checkercells), [`stripeBands`](/docs/primitives/patterns/stripebands), [`ringWaves`](/docs/primitives/patterns/ringwaves), [`dotLattice`](/docs/primitives/patterns/dotlattice),
[`brickCourses`](/docs/primitives/patterns/brickcourses)) bring their own. Color a mask with [`strokeOver`](/docs/primitives/patterns/strokeover) (fill where 0, stroke where 1,
in a chosen color space) or hang it under one color as alpha with [`withAlpha`](/docs/primitives/patterns/withalpha); the result goes
in `paint:`. The halftone and dither words are filters over the layer inside them and go in
`effect:`.

```ts
import {patterns} from 'shaders/std'
```

## Reach for it when

| When you need | Use |
|---|---|
| a two-color checkerboard | [`checkerCells`](/docs/primitives/patterns/checkercells) colored with [`strokeOver`](/docs/primitives/patterns/strokeover) |
| stripes or chevrons that scroll | [`stripeBands`](/docs/primitives/patterns/stripebands), [`zigzagBands`](/docs/primitives/patterns/zigzagbands) |
| rings rippling out from a point | [`ringWaves`](/docs/primitives/patterns/ringwaves) |
| rain or streaks falling across the canvas | [`fallingStreaks`](/docs/primitives/patterns/fallingstreaks) with [`withAlpha`](/docs/primitives/patterns/withalpha) |
| a field of dots, optionally staggered or twinkling | [`dotLattice`](/docs/primitives/patterns/dotlattice) under [`withAlpha`](/docs/primitives/patterns/withalpha) |
| grid lines, honeycombs or triangle lattices | [`cellFrame`](/docs/primitives/patterns/cellframe) with [`gridLines`](/docs/primitives/patterns/gridlines), [`hexLines`](/docs/primitives/patterns/hexlines), [`triangleLines`](/docs/primitives/patterns/trianglelines) |
| every tile a slightly different brightness | [`vary`](/docs/primitives/patterns/vary) with a lattice word's shade output |
| a brick wall | [`brickCourses`](/docs/primitives/patterns/brickcourses) |
| a maze of joined arcs | [`truchetArcs`](/docs/primitives/patterns/truchetarcs) |
| a woven textile | [`weaveThreads`](/docs/primitives/patterns/weavethreads) |
| tumbling 3D cubes | [`isoCubeFaces`](/docs/primitives/patterns/isocubefaces) with [`times`](/docs/primitives/patterns/times), [`mixOf`](/docs/primitives/patterns/mixof), [`opaque`](/docs/primitives/patterns/opaque) |
| a mapped size or thickness that should change per whole cell | [`sampleMapsAtCellCentres`](/docs/primitives/patterns/samplemapsatcellcentres) on the definition's mapSampleUVs field |
| a halftone dot screen over the layer inside | [`dotScreen`](/docs/primitives/patterns/dotscreen) |
| a four-color print with plate angles and misregistration | [`cmykPress`](/docs/primitives/patterns/cmykpress) with [`inkPlate`](/docs/primitives/patterns/inkplate) |
| your own ink press inside a gather build | [`dotScreenMask`](/docs/primitives/patterns/dotscreenmask), [`inkTransmission`](/docs/primitives/patterns/inktransmission) |
| one select prop that swaps whole effect recipes | [`chosenBy`](/docs/primitives/patterns/chosenby) |
| a retro dither | [`pixelGrid`](/docs/primitives/patterns/pixelgrid), [`quantise`](/docs/primitives/patterns/quantise), [`ditherInks`](/docs/primitives/patterns/ditherinks) |
| a color's alpha or RGB on its own | [`alphaOf`](/docs/primitives/patterns/alphaof), [`rgbOf`](/docs/primitives/patterns/rgbof) |

## Example

```ts
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

| Type | What it is |
|---|---|
| `CellFrameConvention` | Which way a lattice's rows and rotation run. |
| `GatherStage` | A value computed per pixel from the layer inside a gather effect, such as a dither level. |
| `InkPlateSpec` | One ink plate of a `cmykPress`: which channel it prints, its screen-angle prop (degrees) and its ink-color prop. |
| `PaintSlot` | What a pattern slot accepts: a prop `p('name')` or another pattern value. |
| `PatternPaint` | A pattern value: something you place in `paint:` or hand to another pattern word, yielding a color or a mask per pixel. |
| `PixelGrid` | The 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. |
| `ScatterOptions` | What `scatterPoint` and `scatterPoints` take. |
| `ScatteredPoint` | One scattered point: where it sits, the pixel's offset from it, and three random 0–1 values for its cell. |

## Words

- [`strokeOver`](/docs/primitives/patterns/strokeover) — Two colors mixed through a mask: `fill` where the mask is 0, `stroke` where it is 1.
- [`withAlpha`](/docs/primitives/patterns/withalpha) — A color with its alpha replaced by a separately built mask.
- [`checkerCells`](/docs/primitives/patterns/checkercells) — A checkerboard mask: 1 on one set of squares, 0 on the other, with clean edges at any size.
- [`stripeBands`](/docs/primitives/patterns/stripebands) — A mask of straight parallel stripes that scroll with the layer's clock.
- [`zigzagBands`](/docs/primitives/patterns/zigzagbands) — A mask of chevron (zigzag) stripes that scroll with the layer's clock.
- [`ringWaves`](/docs/primitives/patterns/ringwaves) — A mask of concentric rings spreading out from a point, animated by the layer's clock.
- [`fallingStreaks`](/docs/primitives/patterns/fallingstreaks) — Streaks that fall across the canvas in columns, each column at its own random speed.
- [`dotLattice`](/docs/primitives/patterns/dotlattice) — A mask of round dots on a square grid, with optional row stagger, drift and twinkle.
- [`cellFrame`](/docs/primitives/patterns/cellframe) — The shared coordinate system of a tiled pattern: how many cells fit down the canvas height and how far the whole lattice is rotated.
- [`gridLines`](/docs/primitives/patterns/gridlines) — Square grid lines drawn in a `cellFrame`, plus a per-cell shade for the fill.
- [`hexLines`](/docs/primitives/patterns/hexlines) — Honeycomb lines (pointy-top hexagons) drawn in a `cellFrame`, plus a per-cell shade.
- [`triangleLines`](/docs/primitives/patterns/trianglelines) — A lattice of equilateral triangles drawn in a `cellFrame`, with rows that can drift.
- [`brickCourses`](/docs/primitives/patterns/brickcourses) — A brick wall: staggered rows with mortar gaps, optional rotation and per-row drift.
- [`truchetArcs`](/docs/primitives/patterns/truchetarcs) — A maze of quarter-circle arcs, two per tile, flipped at random so they join into flowing curves.
- [`weaveThreads`](/docs/primitives/patterns/weavethreads) — Two sets of threads woven over and under each other, returned as a finished color.
- [`isoCubeFaces`](/docs/primitives/patterns/isocubefaces) — Tumbling blocks: three shaded rhombus faces per hexagon that read as a field of 3D cubes.
- [`vary`](/docs/primitives/patterns/vary) — A color lightened or darkened per cell by a shade factor, alpha untouched.
- [`sampleMapsAtCellCentres`](/docs/primitives/patterns/samplemapsatcellcentres) — Makes map-driven props change per whole cell instead of per pixel, so a mapped dot size or line thickness grows cell by cell rather than being cut off mid-cell.
- [`times`](/docs/primitives/patterns/times) — The product of two values: a mask scaled by a prop, an RGB dimmed by a shade, two masks combined.
- [`mixOf`](/docs/primitives/patterns/mixof) — A straight blend from one value to another by an amount from 0 to 1.
- [`alphaOf`](/docs/primitives/patterns/alphaof) — The alpha channel of a color, as a number per pixel.
- [`rgbOf`](/docs/primitives/patterns/rgbof) — The RGB channels of a color, without its alpha.
- [`opaque`](/docs/primitives/patterns/opaque) — An RGB value finished as a fully opaque color.
- [`dotScreen`](/docs/primitives/patterns/dotscreen) — A classic halftone filter: the layer inside it redrawn as a grid of dots that grow where it is bright.
- [`cmykPress`](/docs/primitives/patterns/cmykpress) — A four-color print filter: the layer inside it separated into ink plates, each screened into dots at its own angle and laid down on paper in order.
- [`inkPlate`](/docs/primitives/patterns/inkplate) — Declares one ink plate for `cmykPress`.
- [`dotScreenMask`](/docs/primitives/patterns/dotscreenmask) — The dot coverage of one halftone screen: 1 inside a dot, 0 between, with the dot size set by an ink amount.
- [`inkTransmission`](/docs/primitives/patterns/inktransmission) — How much light passes one ink plate: white where the dot mask is 0, the ink color where it is 1.
- [`chosenBy`](/docs/primitives/patterns/chosenby) — Picks one whole effect recipe from a select prop, decided when the shader compiles.
- [`pixelGrid`](/docs/primitives/patterns/pixelgrid) — The pixel grid of a dither: the layer inside it chopped into square cells of a given size.
- [`quantise`](/docs/primitives/patterns/quantise) — Reduces each grid cell of the layer inside to 0 or 1 using a dither pattern.
- [`ditherInks`](/docs/primitives/patterns/ditherinks) — A dither filter: colors the 0/1 levels from `quantise`, either with two colors of your own or with darkened and brightened versions of the layer's own pixels.
- [`scatterPoint`](/docs/primitives/patterns/scatterpoint) — One random point in each cell of a square grid: the classic scatter for glitter, stars, dust and sparkles.
- [`scatterPoints`](/docs/primitives/patterns/scatterpoints) — The scattered points of the four grid cells nearest the pixel, so anything drawn up to half a cell from its point shows whole, never clipped at a cell edge.