Vivid.Arc (vivid v0.4.5)

Copy Markdown View Source

This module represents an Arc, otherwise known as a circle segment.

Example

iex> use Vivid
...> Arc.init(Point.init(10,10), 10, 0, 45)
...> |> to_string()
"@@@@@@\n" <>
"@@@  @\n" <>
"@@@ @@\n" <>
"@@ @@@\n" <>
"@@ @@@\n" <>
"@  @@@\n" <>
"@ @@@@\n" <>
"@ @@@@\n" <>
"@ @@@@\n" <>
"@@@@@@\n"

Summary

Functions

Returns the center point of an arc.

Changes the center point of arc.

Returns the radius of an arc.

Change the radius of arc.

Returns the range of the arc.

Change the range of an arc.

Returns the start angle of an arc.

Change the start angle of an arc.

Returns the number of steps in the arc.

Changes the number of steps in arc.

Converts the arc into a Path, which is used for a bunch of things like Transforms, Bounds calculation, Rasterization, etc.

Types

t()

@type t() :: %Vivid.Arc{
  center: Vivid.Point.t(),
  radius: number(),
  range: term(),
  start_angle: number(),
  steps: integer()
}

Functions

center(arc)

@spec center(t()) :: Vivid.Point.t()

Returns the center point of an arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.center
Vivid.Point.init(10, 10)

center(arc, point)

@spec center(t(), Vivid.Point.t()) :: t()

Changes the center point of arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.center(Vivid.Point.init(15,15))
...> |> Vivid.Arc.center
Vivid.Point.init(15, 15)

init(center, radius, start_angle, range, steps \\ 12)

@spec init(Vivid.Point.t(), number(), number(), number(), integer()) :: t()

Creates an Arc.

  • center is a Point definining the center point of the arc's parent circle.
  • radius is the radius of the parent circle.
  • start_angle is the angle at which to start drawing the arc, 0 is the parallel to the X axis, to the left.
  • range is the number of degrees to draw the arc.
  • steps the arc is drawn by dividing it into a number of lines. Defaults to 12.

Examples

iex> Vivid.Arc.init(Vivid.Point.init(5,5), 4, 45, 15)
%Vivid.Arc{
  center:      %Vivid.Point{x: 5, y: 5},
  radius:      4,
  start_angle: 45,
  range:       15,
  steps:       12
}

radius(arc)

@spec radius(t()) :: number()

Returns the radius of an arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.radius
5

radius(arc, radius)

@spec radius(t(), number()) :: t()

Change the radius of arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.radius(10)
...> |> Vivid.Arc.radius
10

range(arc)

@spec range(t()) :: number()

Returns the range of the arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.range
90

range(arc, theta)

@spec range(t(), number()) :: t()

Change the range of an arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.range(270)
...> |> Vivid.Arc.range
270

start_angle(arc)

@spec start_angle(t()) :: number()

Returns the start angle of an arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.start_angle
0

start_angle(arc, theta)

@spec start_angle(t(), number()) :: t()

Change the start angle of an arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.start_angle(45)
...> |> Vivid.Arc.start_angle
45

steps(arc)

@spec steps(t()) :: integer()

Returns the number of steps in the arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.steps
12

steps(arc, steps)

@spec steps(t(), integer()) :: t()

Changes the number of steps in arc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 12)
...> |> Vivid.Arc.steps(19)
...> |> Vivid.Arc.steps
19

to_path(arc)

@spec to_path(t()) :: Vivid.Path.t()

Converts the arc into a Path, which is used for a bunch of things like Transforms, Bounds calculation, Rasterization, etc.

Example

iex> Vivid.Arc.init(Vivid.Point.init(10,10), 5, 0, 90, 3)
...> |> Vivid.Arc.to_path
Vivid.Path.init([Vivid.Point.init(5, 10), Vivid.Point.init(6, 13), Vivid.Point.init(8, 14), Vivid.Point.init(10, 15)])