Skip to content
pattern

pattern

Mojo module 🡭

pattern

Raster patterns as a fill source: PatternSource, a ColorSource (gradient.mojo) that samples a small Canvas tile instead of projecting onto a gradient axis. Consumed by fill_path_pattern/ fill_path_pattern_aa (path.mojo) and fill_rect_pattern (canvas.shapes.rects), the pattern-fill counterparts of the gradient fills those modules already carry.

PatternSource needs a Canvas to hold its tile, which is why it lives in its own module rather than alongside LinearGradient/ RadialGradient/ConicGradient in gradient.mojo: those three only ever need Color, and keeping that file free of a Canvas dependency keeps it the lightweight thing every gradient-aware fill imports.

hatch_tile builds the tile for the common chart case – diagonal lines, a cross-hatch, dots, or axis-aligned lines – rendered once to a small canvas with the existing anti-aliased primitives, ready to hand to PatternSource.

Structs

  • Extend: How PatternSource.color_at samples outside the tile’s own [0, width) x [0, height) bounds.
  • PatternSource: A ColorSource that samples a raster tile – the fill source a pattern/image fill queries per pixel, mirroring how LinearGradient/RadialGradient/ConicGradient project a point onto a gradient axis instead.
  • Hatch: Which pattern hatch_tile renders.

Functions