Blendend.Canvas.Fill (blendend v0.2.0)
View SourceFill functions for Blendend.Canvas to paint a
geometry on the canvas with a style (color, gradient or pattern).
Prefer the Blendend.Draw macros; they call into this
module under the hood.
use Blendend.Draw
draw 200, 200, "fill_example.png" do
clear fill: rgb(240, 240, 240)
rect 30, 30, 140, 140, fill: rgb(255, 80, 80)
circle 100, 100, 40, fill: rgb(255, 255, 255), alpha: 0.7
end
Summary
Functions
Fills a box given by corner coordinates {x0, y0, x1, y1}.
Same as box/6, but returns the canvas and raises on error.
Fills multiple boxes in one call.
Same as box_array/3, but returns the canvas and raises on error.
Fills a chord (arc + straight line between its endpoints).
Same as chord/8, but returns the canvas and raises on error.
Fills a circle at (cx, cy) with radius r.
Same as circle/5, but returns the canvas and raises on error.
Fills an ellipse centered at (cx, cy) with radii rx and ry.
Same as ellipse/6, but returns the canvas and raises on error.
Fills path on canvas using the given style options.
Same as path/3, but returns the canvas and raises on error.
Fills a pie/sector shape.
Same as pie/8, but returns the canvas and raises on error.
Fills a polygon from a list of {x, y} points.
Same as polygon/3, but returns the canvas and raises on error.
Fills an axis–aligned rectangle (x, y, w, h).
Same as rect/6, but returns the canvas and raises on error.
Fills multiple rectangles in one call.
Same as rect_array/3, but returns the canvas and raises on error.
Fills a rounded rectangle (x, y, w, h) with corner radii (rx, ry).
Same as round_rect/8, but returns the canvas and raises on error.
Fills a triangle specified by its three vertices.
Same as triangle/8, but returns the canvas and raises on error.
Fills a UTF-8 text string on canvas using a font.
Same as utf8_text/6, but returns the canvas and raises on error.
Types
@type canvas() :: Blendend.Canvas.t()
@type opts() :: keyword()
Functions
Fills a box given by corner coordinates {x0, y0, x1, y1}.
Uses the same style options as path/3.
Same as box/6, but returns the canvas and raises on error.
On success, returns canvas.
On failure, raises Blendend.Error.
@spec box_array(canvas(), [{number(), number(), number(), number()}], opts()) :: :ok | {:error, term()}
Fills multiple boxes in one call.
boxes is a list of {x0, y0, x1, y1} tuples.
Uses the same style options as path/3.
Same as box_array/3, but returns the canvas and raises on error.
@spec chord( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: :ok | {:error, term()}
Fills a chord (arc + straight line between its endpoints).
Parameters describe an ellipse centered at (cx, cy) with radii rx, ry
and angles start_angle / sweep_angle in radians.
Uses the same style options as path/3.
@spec chord!( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: canvas()
Same as chord/8, but returns the canvas and raises on error.
Fills a circle at (cx, cy) with radius r.
Uses the same style options as path/3.
Same as circle/5, but returns the canvas and raises on error.
On success, returns canvas.
On failure, raises Blendend.Error.
Fills an ellipse centered at (cx, cy) with radii rx and ry.
Uses the same style options as path/3.
Same as ellipse/6, but returns the canvas and raises on error.
@spec path(canvas(), Blendend.Path.t(), opts()) :: :ok | {:error, term()}
Fills path on canvas using the given style options.
path must be a Blendend.Path.t().
Style options
We normally provide exactly one brush with :fill
and optionally decorate it with :alpha and/or :comp_op. If no brush is
provided
The opts keyword list controls the fill style. The style layer currently
understands:
:fill:
– solid brush, created withBlendend.Style.Color.*– gradient brush, created withBlendend.Style.Gradient.*– image pattern, created withBlendend.Style.Pattern.create/1:alpha– extra opacity multiplier (values are0.0..1.0):comp_op– compositing operator atom:src_over(default):src_copy:src_in:src_out:dst_over:dst_copy:dst_in:dst_out:dst_atop:difference:multiply:screen:overlay:xor:clear:plus:minus:modulate:darken:lighten:color_dodge:color_burn:linear_burn:pin_light:hard_light:soft_light:exclusionThose terms and the mathematics behind them are clearly explained on this page: Advanced compositing features
Examples
alias Blendend.{Canvas, Path, Style}
alias Blendend.Canvas.Fill
canvas = Canvas.new!(200, 200)
path =
Path.new!()
|> Path.move_to!(10, 10)
|> Path.line_to!(190, 10)
|> Path.line_to!(100, 180)
|> Path.close!()
:ok =
Fill.path(canvas, path,
fill: Style.color(255, 0, 0),
alpha: 0.9,
comp_op: :src_over)On success, returns :ok.
On failure, returns {:error, reason} from the NIF.
@spec path!(canvas(), Blendend.Path.t(), opts()) :: canvas()
Same as path/3, but returns the canvas and raises on error.
On success, returns canvas.
On failure, raises Blendend.Error.
@spec pie( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: :ok | {:error, term()}
Fills a pie/sector shape.
Same parameters as chord/8, but the arc is also connected back to the
ellipse center.
Uses the same style options as path/3.
@spec pie!( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: canvas()
Same as pie/8, but returns the canvas and raises on error.
Fills a polygon from a list of {x, y} points.
Uses the same style options as path/3.
Same as polygon/3, but returns the canvas and raises on error.
Fills an axis–aligned rectangle (x, y, w, h).
(x, y) is the top–left corner; w and h are width and height.
Uses the same style options as path/3.
Same as rect/6, but returns the canvas and raises on error.
On success, returns canvas.
On failure, raises Blendend.Error.
@spec rect_array(canvas(), [{number(), number(), number(), number()}], opts()) :: :ok | {:error, term()}
Fills multiple rectangles in one call.
rects is a list of {x, y, w, h} tuples.
Uses the same style options as path/3.
Same as rect_array/3, but returns the canvas and raises on error.
@spec round_rect( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: :ok | {:error, term()}
Fills a rounded rectangle (x, y, w, h) with corner radii (rx, ry).
Uses the same style options as path/3.
@spec round_rect!( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: canvas()
Same as round_rect/8, but returns the canvas and raises on error.
@spec triangle( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: :ok | {:error, term()}
Fills a triangle specified by its three vertices.
Uses the same style options as path/3.
@spec triangle!( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: canvas()
Same as triangle/8, but returns the canvas and raises on error.
@spec utf8_text( canvas(), Blendend.Text.Font.t(), number(), number(), String.t(), opts() ) :: :ok | {:error, term()}
Fills a UTF-8 text string on canvas using a font.
Draws the text with its origin at (x, y) in the current canvas transform.
opts is the same style keyword list used by path/3 (for example
:color, :gradient, :alpha, :comp_op).
On success, returns :ok.
On failure, returns {:error, reason}.
@spec utf8_text!( canvas(), Blendend.Text.Font.t(), number(), number(), String.t(), opts() ) :: canvas()
Same as utf8_text/6, but returns the canvas and raises on error.
On success, returns canvas.
On failure, raises Blendend.Error.