vivid v0.2.1 Vivid.Circle

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

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

Types

t()
t

Functions

center(circle)

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)
circumference(Vivid.Circle.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)
init(Vivid.Point.t, number) :: Vivid.Circle.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<{5, 5}>, radius: 4]>
radius(circle)
radius(Cricle.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)

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.

If unspecified then 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"

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"
to_polygon(circle, steps)
to_polygon(Vivid.Circle.t, number) :: Vivid.Polygon.t