Vivid.Circle (vivid v0.4.5)

Copy Markdown View Source

Represents a circle based on it's center point and radius.

Example

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

Summary

Functions

Returns the center point of a circle.

Returns the circumference of a circle.

Creates a circle from a point in 2D space and a radius.

Returns the radius of a circle.

Convert the circle into a Polygon.

Convert the circle into a Polygon with a specific number of vertices.

Types

t()

@type t() :: %Vivid.Circle{center: Vivid.Point.t(), fill: boolean(), radius: number()}

Functions

center(circle)

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

Returns the center point of a circle.

Example

iex> Vivid.Circle.init(Vivid.Point.init(5,5), 4)
...> |> Vivid.Circle.center
%Vivid.Point{x: 5, y: 5}

circumference(circle)

@spec circumference(t()) :: number()

Returns the circumference of a circle.

Example

iex> Vivid.Circle.init(Vivid.Point.init(5,5), 4)
...> |> Vivid.Circle.circumference
25.132741228718345

init(point, radius)

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

Creates a circle from a point in 2D space and a radius.

Example

iex> Vivid.Circle.init(Vivid.Point.init(5,5), 4)
%Vivid.Circle{center: Vivid.Point.init(5, 5), radius: 4}

radius(circle)

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

Returns the radius of a circle.

Example

iex> Vivid.Circle.init(Vivid.Point.init(5,5), 4)
...> |> Vivid.Circle.radius
4

to_polygon(circle)

@spec to_polygon(t()) :: Vivid.Polygon.t()

Convert the circle into a Polygon.

We convert a circle into a Polygon whenever we Transform or render it, so sometimes it might be worth doing it yourself and specifying how many vertices the polygon should have.

When unspecified steps is set to the diameter of the circle rounded to the nearest integer.

Examples

iex> use Vivid
...> Circle.init(Point.init(5,5), 5)
...> |> Circle.to_polygon
...> |> to_string
"@@@@@@@@@@@@@\n" <>
"@@@@     @@@@\n" <>
"@@@ @@@@@ @@@\n" <>
"@@ @@@@@@@ @@\n" <>
"@@ @@@@@@@ @@\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@ @@@@@@@@@ @\n" <>
"@@ @@@@@@@ @@\n" <>
"@@ @@@@@@@ @@\n" <>
"@@@ @@@@@ @@@\n" <>
"@@@@     @@@@\n" <>
"@@@@@@@@@@@@@\n"

to_polygon(circle, steps)

@spec to_polygon(t(), number()) :: Vivid.Polygon.t()

Convert the circle into a Polygon with a specific number of vertices.

We convert a circle into a Polygon whenever we Transform or render it, so sometimes it might be worth doing it yourself and specifying how many vertices the polygon should have.

Examples

iex> use Vivid
...> Circle.init(Point.init(5,5), 5)
...> |> Circle.to_polygon(3)
...> |> to_string
"@@@@@@@@@@@\n" <>
"@  @@@@@@@@\n" <>
"@ @  @@@@@@\n" <>
"@ @@@  @@@@\n" <>
"@ @@@@@  @@\n" <>
"@ @@@@@@@ @\n" <>
"@ @@@@@  @@\n" <>
"@ @@@  @@@@\n" <>
"@ @@ @@@@@@\n" <>
"@   @@@@@@@\n" <>
"@ @@@@@@@@@\n" <>
"@@@@@@@@@@@\n"