PatternSource
Mojo struct 🡭
PatternSource
@memory_only
struct PatternSourceA 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.
Holds its own copy of tile, so drawing into the caller’s canvas
afterward has no effect on a pattern already built from it.
Fields
- tile (
Canvas) - extend (
Extend) - ox (
Float64) - oy (
Float64)
Implemented traits
AnyType, ColorSource, Deinitable, Movable
Methods
__init__
fn def __init__(out self, tile: Canvas, extend: Extend = Extend.REPEAT, ox: Float64 = 0, oy: Float64 = 0)Args: tile: The pattern’s raster tile. Copied into the source, so the caller’s canvas remains independent afterward. extend: How to sample outside the tile’s bounds – see Extend. ox: Device-space x where the tile’s own (0, 0) pixel sits. oy: Device-space y where the tile’s own (0, 0) pixel sits.
Args:
- tile (
Canvas) - extend (
Extend) - ox (
Float64) - oy (
Float64) - self (
Self)
Returns:
Self
color_at
fn def color_at(self, x: Float64, y: Float64) -> ColorThe tile’s color at (x, y): shift by the offset, round to the nearest tile pixel, then wrap/clamp/reject that coordinate per extend.
Args:
- self (
Self) - x (
Float64): Point x. - y (
Float64): Point y.
Returns:
Color: The sampled tile pixel, or transparent black under
Extend.NONE outside the tile, or if the tile is empty.