Blendend.Canvas.Stroke (blendend v0.2.0)
View SourceStroke functions for Blendend.Canvas to stroke 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 240, 160, "stroke_example.png" do
clear fill: rgb(250, 250, 250)
line 20, 20, 220, 140, stroke: rgb(30, 30, 30), stroke_width: 4
circle 120, 80, 40, stroke: rgb(200, 60, 60), stroke_width: 3
end
Summary
Functions
Strokes an elliptical arc.
Same as arc/8, but returns the canvas and raises on error.
Strokes a box {x0, y0, x1, y1}.
Same as box/6, but returns the canvas and raises on error.
Strokes multiple boxes in one call.
Same as box_array/3, but returns the canvas and raises on error.
Strokes a chord/segment of an ellipse (arc + straight line between endpoints).
Same as chord/8, but returns the canvas and raises on error.
Strokes a circle at (cx, cy) with radius r.
Same as circle/5, but returns the canvas and raises on error.
Strokes an ellipse at (cx, cy) with radii rx and ry.
Same as ellipse/6, but returns the canvas and raises on error.
Strokes a line from (x0, y0) to (x1, y1).
Same as line/6, but returns the canvas and raises on error.
Strokes path on canvas using the given stroke options.
Same as path/3, but returns the canvas and raises on error.
Strokes a pie/sector shape.
Same as pie/8, but returns the canvas and raises on error.
Strokes a closed polygon given as a list of {x, y} points.
Same as polygon/3, but returns the canvas and raises on error.
Strokes a polyline given as a list of {x, y} points.
Same as polyline/3, but returns the canvas and raises on error.
Strokes a rectangle (x, y, w, h).
Same as rect/6, but returns the canvas and raises on error.
Strokes multiple rectangles in one call.
Same as rect_array/3, but returns the canvas and raises on error.
Strokes 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.
Strokes a triangle specified by its three vertices.
Same as triangle/8, but returns the canvas and raises on error.
Strokes a UTF-8 text string on canvas using font.
Same as utf8_text/6, but returns the canvas and raises on error.
Types
@type canvas() :: Blendend.Canvas.t()
@type opts() :: keyword()
Functions
@spec arc( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: :ok | {:error, term()}
Strokes an elliptical arc.
Parameters describe an ellipse centered at (cx, cy) with radii rx, ry
and angles start_angle / sweep_angle in radians.
Uses the same stroke options as path/3.
@spec arc!( canvas(), number(), number(), number(), number(), number(), number(), opts() ) :: canvas()
Same as arc/8, but returns the canvas and raises on error.
Strokes a box {x0, y0, x1, y1}.
Uses the same stroke options as path/3.
Same as box/6, but returns the canvas and raises on error.
@spec box_array(canvas(), [{number(), number(), number(), number()}], opts()) :: :ok | {:error, term()}
Strokes multiple boxes in one call.
boxes is a list of {x0, y0, x1, y1} tuples.
Uses the same stroke 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()}
Strokes a chord/segment of an ellipse (arc + straight line between endpoints).
Uses the same stroke 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.
Strokes a circle at (cx, cy) with radius r.
Uses the same stroke options as path/3.
Same as circle/5, but returns the canvas and raises on error.
Strokes an ellipse at (cx, cy) with radii rx and ry.
Uses the same stroke options as path/3.
Same as ellipse/6, but returns the canvas and raises on error.
Strokes a line from (x0, y0) to (x1, y1).
Uses the same stroke options as path/3.
Same as line/6, but returns the canvas and raises on error.
@spec path(canvas(), Blendend.Path.t(), opts()) :: :ok | {:error, term()}
Strokes path on canvas using the given stroke options.
path must be a Blendend.Path.t().
Stroke options
The opts keyword list controls the stroke appearance. Common keys:
:stroke- stroke brush (solid color), from
Blendend.Style.Color.*– gradient stroke brush, fromBlendend.Style.Gradient.*– pattern stroke brush, fromBlendend.Style.Pattern.create/1(default is black color)
- stroke brush (solid color), from
:width– stroke width as a float (default: 1.0):cap– cap style at both ends, or:start_cap/:end_capto set independently::butt(default):square:round:round_rev:triangle:triangle_rev
:join– join style between segments::miter_clip(default):miter_bevel:miter_round:bevel:round
:miter_limit– miter limit as float (only for:miterjoins):comp_op– compositing operator atom. SeeBlendend.Canvas.Fill.path/3for viable options.:alpha- extra stroke opacity multiplier (values are0.0..1.0) If you omit brush options, default values are set.
Examples
alias Blendend.{Canvas, Path, Style}
alias Blendend.Canvas.Stroke
canvas = Canvas.new!(200, 200)
path =
Path.new!()
|> Path.move_to!(20, 20)
|> Path.line_to!(180, 180)
:ok =
Stroke.path(canvas, path,
stroke_color: Style.color(0, 0, 0),
width: 2.0,
cap: :round
)On success, returns :ok.
On failure, returns {:error, reason}.
@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()}
Strokes a pie/sector shape.
Same parameters as chord/8, but the arc is also connected back to the
ellipse center.
Uses the same stroke 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.
Strokes a closed polygon given as a list of {x, y} points.
Uses the same stroke options as path/3.
Same as polygon/3, but returns the canvas and raises on error.
Strokes a polyline given as a list of {x, y} points.
Uses the same stroke options as path/3.
Same as polyline/3, but returns the canvas and raises on error.
Strokes a rectangle (x, y, w, h).
Uses the same stroke options as path/3.
Same as rect/6, but returns the canvas and raises on error.
@spec rect_array(canvas(), [{number(), number(), number(), number()}], opts()) :: :ok | {:error, term()}
Strokes multiple rectangles in one call.
rects is a list of {x, y, w, h} tuples.
Uses the same stroke 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()}
Strokes a rounded rectangle (x, y, w, h) with corner radii (rx, ry).
Uses the same stroke 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()}
Strokes a triangle specified by its three vertices.
Uses the same stroke 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()}
Strokes a UTF-8 text string on canvas using font.
Draws the text with its origin at (x, y).
opts reuses the same stroke options as path/3
(:stroke_color, :stroke_width, etc.).
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.