hatch

hatch

Fill — plotter marks via clipped stroke patterns. See Fills.

Imports

import {
  hatchParallel, hatchCross, hatchWeave, hatchStochastic,
  hatchPerpendicular, hatchConcentric, hatch,
  type ParallelHatchOptions, type WeaveHatchOptions,
  type StochasticHatchOptions, type PerpendicularHatchOptions,
  type ConcentricHatchOptions,
} from 'pattapatta'
// or from 'pattapatta/hatch'

hatchParallel(path, options?: ParallelHatchOptions) → Segment[]

OptionDefaultMeaning
angleπ/4Line direction (radians)
spacing0.15Perpendicular spacing
countautoLine count; omit to cover the whole path AABB
lengthbbox diagonalPre-clip half-length
centerbbox centerField center

hatchCross(path, options?)

Two perpendicular parallel fields.

hatchWeave(path, options?: WeaveHatchOptions) → Segment[]

ABC fabric weave over the path AABB, clipped to the path.

OptionDefaultMeaning
cellSize~1/12 shorter sideGrid cell size
A / B / C1 / 1 / 1Weft run / warp run / row shift

hatchStochastic(path, options?: StochasticHatchOptions) → Segment[]

Random non-intersecting segments in the AABB, clipped to the path.

OptionDefaultMeaning
count40Segments before clip
length—Fixed length (overrides min/max)
seed1PRNG seed

hatchPerpendicular(path, options?) → Segment[]

Perimeter ticks centered on the boundary (outline texture, not area fill).

hatchConcentric(path, options?) → Path[]

Nested inward offset shells as closed stroke paths.

Examples

Parallel

Parallel hatch

const strokes = hatchParallel(createRect(15, 15, 70, 70), {
  spacing: 6, angle: Math.PI / 4,
})

Cross

Cross hatch

const strokes = hatchCross(createRect(15, 15, 70, 70), { spacing: 8 })

Weave

Weave hatch

const strokes = hatchWeave(createRect(15, 15, 70, 70), {
  cellSize: 8, A: 2, B: 2, C: 1,
})

Stochastic

Stochastic hatch

const strokes = hatchStochastic(createRect(15, 15, 70, 70), {
  count: 50, length: 18, seed: 3,
})

Concentric

Concentric hatch

const shells = hatchConcentric(createRect(15, 15, 70, 70), {
  spacing: 6, count: 5,
})

Serialize segments with toSvg(group(segmentsToOpenPaths(strokes))). Concentric shells are already closed Paths — pass them to group(shells).