Blendend.Style.Pattern (blendend v0.3.0)

View Source

A pattern wraps a Blendend.Image and can be used as a fill or stroke style via canvas operations (for example by passing fill: pattern in style options).

Use patterns when you want an image as "paint" inside shapes or text.

A pattern wraps a Blendend.Image.t() and can be used as a fill or stroke style via canvas operations (for example by passing fill: pat in style options).

Example:

img = Blendend.Image.from_file!("texture.png")
pat        = Blendend.Style.Pattern.create!(img)

# used as fill:
rect 0, 0, 400, 400, fill: pat

Summary

Functions

Creates a pattern from an existing Blendend.Image.

Same as create/1, but raises on failure.

Resets the pattern's transform back to identity.

Sets the extend mode used when sampling a pattern.

Sets the transform matrix used when sampling a pattern.

Types

extend_mode()

@type extend_mode() ::
  :pad
  | :repeat
  | :reflect
  | :pad_x_repeat_y
  | :pad_x_reflect_y
  | :repeat_x_pad_y
  | :repeat_x_reflect_y
  | :reflect_x_pad_y
  | :reflect_x_repeat_y

t()

@opaque t()

Functions

create(img)

@spec create(Blendend.Image.t()) :: {:ok, t()} | {:error, term()}

Creates a pattern from an existing Blendend.Image.

Returns {:ok, pattern} or {:error, reason}.

create!(img)

@spec create!(Blendend.Image.t()) :: t()

Same as create/1, but raises on failure.

On success, returns pattern.

On failure, raises Blendend.Error.

reset_transform(pattern)

@spec reset_transform(t()) :: :ok | {:error, term()}

Resets the pattern's transform back to identity.

set_extend(pattern, mode)

@spec set_extend(t(), extend_mode()) :: :ok | {:error, term()}

Sets the extend mode used when sampling a pattern.

The extend mode decides how the pattern is sampled when coordinates land outside the wrapped image. Supported modes:

  • :pad / :repeat / :reflect – apply the mode on both axes
  • :pad_x_repeat_y / :pad_x_reflect_y – pad on X, repeat or reflect on Y
  • :repeat_x_pad_y / :repeat_x_reflect_y – repeat on X, pad or reflect on Y
  • :reflect_x_pad_y / :reflect_x_repeat_y – reflect on X, pad or repeat on Y

Returns :ok or {:error, reason}.

set_transform(pattern, matrix)

@spec set_transform(t(), Blendend.Matrix2D.t()) :: :ok | {:error, term()}

Sets the transform matrix used when sampling a pattern.