Blendend.Effects (blendend v0.2.0)

View Source

This module contains functions to add effects to geometries.

It currently provides gaussian blur filter and shadow effects on top of it. The NIF implementation is based on https://blog.ivank.net/fastest-gaussian-blur.html.

Gaussian blur is applied after rasterizing a path into an offscreen image, then composited back on the destination canvas. So applying a blur to a shape is more expensive than most other operations in blendend.

Examples:

use Blendend.Draw
clear(fill: rgb(0x42, 0x4D, 0x8C))

ring =
  path do
    add_circle(220, 210, 96.0)
  end

blur_path(ring, 4,
  mode: :stroke,
  stroke: rgb(90, 200, 255),
  stroke_width: 10.0
)

Summary

Functions

Render a blurred copy of path onto canvas.

Same as blur_path/4, but raises on failure and returns the canvas.

Blur a path with an offset to create a soft shadow or glow.

Same as shadow_path/6, but raises on failure and returns the canvas.

Types

blur_mode()

@type blur_mode() :: :fill | :stroke | :fill_and_stroke | :both

Functions

blur_path(canvas, path, sigma, opts \\ [])

@spec blur_path(Blendend.Canvas.t(), Blendend.Path.t(), number(), keyword()) ::
  :ok | {:error, term()}

Render a blurred copy of path onto canvas.

  • sigma controls blur strength in pixels (roughly radius = 3 * sigma).
  • options:
    • :mode:fill, :stroke, or :both (alias :fill_and_stroke); (defaults to fill if none set)
    • :offset{dx, dy} translation before compositing (useful for shadows); values are floats
    • :resolution – scale factor 0 < r ≤ 1.0 to render/blur (If blurring feels slow, tune this down. Defaults to 1.0)

blur_path!(canvas, path, sigma, opts \\ [])

Same as blur_path/4, but raises on failure and returns the canvas.

shadow_path(canvas, path, dx, dy, sigma, opts \\ [])

@spec shadow_path(
  Blendend.Canvas.t(),
  Blendend.Path.t(),
  number(),
  number(),
  number(),
  keyword()
) ::
  :ok | {:error, term()}

Blur a path with an offset to create a soft shadow or glow.

dx/dy shift the blurred image; other options are forwarded to blur_path/4.

shadow_path!(canvas, path, dx, dy, sigma, opts \\ [])

@spec shadow_path!(
  Blendend.Canvas.t(),
  Blendend.Path.t(),
  number(),
  number(),
  number(),
  keyword()
) ::
  Blendend.Canvas.t()

Same as shadow_path/6, but raises on failure and returns the canvas.