2016-12-21 13:34:16 +13:00
|
|
|
defmodule Vivid do
|
2017-01-02 13:57:02 +13:00
|
|
|
defmacro __using__(_opts) do
|
|
|
|
quote do
|
|
|
|
alias Vivid.{Arc, Bounds, Buffer, Circle, Font, Frame, Group, Font, Frame,
|
2017-01-02 20:47:49 +13:00
|
|
|
Group, Line, Path, Point, Polygon, Rasterize, RGBA, Transform,
|
|
|
|
Box}
|
2017-01-02 13:57:02 +13:00
|
|
|
end
|
2016-12-22 14:04:29 +13:00
|
|
|
end
|
2017-01-03 14:13:35 +13:00
|
|
|
|
|
|
|
@moduledoc ~S"""
|
|
|
|
Vivid is a 2D rendering engine implemented purely in Elixir.
|
|
|
|
|
|
|
|
## Examples
|
|
|
|
|
|
|
|
Drawing a box on the frame
|
|
|
|
|
|
|
|
iex> use Vivid
|
|
|
|
...> frame = Frame.init(40, 20, RGBA.white)
|
|
|
|
...> box = Box.init(Point.init(2,2), Point.init(12,12))
|
|
|
|
...> frame
|
|
|
|
...> |> Frame.push(box, RGBA.black)
|
|
|
|
...> |> to_string
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
|
|
|
|
|
|
And now add a circle.
|
|
|
|
|
|
|
|
iex> use Vivid
|
|
|
|
...> frame = Frame.init(40, 20, RGBA.white)
|
|
|
|
...> box = Box.init(Point.init(2,2), Point.init(12,12))
|
|
|
|
...> circle = Circle.init(Point.init(20, 10), 5)
|
|
|
|
...> frame
|
|
|
|
...> |> Frame.push(box, RGBA.black)
|
|
|
|
...> |> Frame.push(circle, RGBA.init(0.5, 0.5, 0.5, 1))
|
|
|
|
...> |> to_string
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"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
...> circle = Circle.init(Point.init(20, 10), 5)
|
|
|
|
...> triangle = Circle.init(Point.init(30, 7), 5)
|
|
|
|
...> |> Circle.to_polygon(3)
|
|
|
|
...> frame
|
|
|
|
...> |> Frame.push(box, RGBA.black)
|
|
|
|
...> |> Frame.push(circle, RGBA.init(0.5, 0.5, 0.5, 1))
|
|
|
|
...> |> Frame.push(triangle, RGBA.init(0.8, 0.8, 0.8, 1))
|
|
|
|
...> |> to_string
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@:::::@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@:@@@@@:@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@:@@@@@@@:@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@:@@@@@@@:@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@:@@@@@@@@@:@**@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@:@@@@@@@@@:@*@**@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@:@@@@@@@@@:@*@@@**@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@:@@@@@@@:@@*@@@@@**@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@:@@@@@@@:@@@*@@@@@@*@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@:@@@@@:@@@@*@@@@**@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@:::::@@@@@*@@**@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@***@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@ @@@@@@@@@@@@@@@*@@@@@@@@@@@\n" <>
|
|
|
|
"@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
|
|
|
|
|
|
And rotate the box.
|
|
|
|
|
|
|
|
iex> use Vivid
|
|
|
|
...> frame = Frame.init(40, 20, RGBA.white)
|
|
|
|
...> box = Box.init(Point.init(2,2), Point.init(12,12))
|
|
|
|
...> |> Transform.rotate(45)
|
|
|
|
...> |> Transform.apply
|
|
|
|
...> circle = Circle.init(Point.init(20, 10), 5)
|
|
|
|
...> triangle = Circle.init(Point.init(30, 7), 5)
|
|
|
|
...> |> Circle.to_polygon(3)
|
|
|
|
...> frame
|
|
|
|
...> |> Frame.push(box, RGBA.black)
|
|
|
|
...> |> Frame.push(circle, RGBA.init(0.5, 0.5, 0.5, 1))
|
|
|
|
...> |> Frame.push(triangle, RGBA.init(0.8, 0.8, 0.8, 1))
|
|
|
|
...> |> to_string
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@:::::@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@:@@@@@:@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@:@@@@@@@:@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@:@@@@@@@:@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@ @@@@@@:@@@@@@@@@:@**@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@ @@ @@@@:@@@@@@@@@:@*@**@@@@@@@@@\n" <>
|
|
|
|
"@@@@ @@@@@@ @@:@@@@@@@@@:@*@@@**@@@@@@@\n" <>
|
|
|
|
"@@@ @@@@@@@@@ @:@@@@@@@:@@*@@@@@**@@@@@\n" <>
|
|
|
|
"@ @@@@@@@@@ @@:@@@@@@@:@@@*@@@@@@*@@@@\n" <>
|
|
|
|
" @@@@@@@@@ @@@@@:@@@@@:@@@@*@@@@**@@@@@\n" <>
|
|
|
|
"@@ @@@@@@ @@@@@@@:::::@@@@@*@@**@@@@@@@\n" <>
|
|
|
|
"@@@@ @@ @@@@@@@@@@@@@@@@@@***@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@ @@@@@@@@@@@@@@@@@@@@*@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
|
|
|
|
|
|
|
|
And apply a bunch of arbitrary transformations
|
|
|
|
|
|
|
|
iex> use Vivid
|
|
|
|
...> frame = Frame.init(40, 20, RGBA.white)
|
|
|
|
...> box = Box.init(Point.init(2,2), Point.init(12,12))
|
|
|
|
...> |> Transform.rotate(45)
|
|
|
|
...> |> Transform.scale(0.75)
|
|
|
|
...> |> Transform.translate(10, 10)
|
|
|
|
...> |> Transform.apply
|
|
|
|
...> circle = Circle.init(Point.init(20, 10), 5)
|
|
|
|
...> |> Transform.fill(frame)
|
|
|
|
...> |> Transform.center(frame)
|
|
|
|
...> |> Transform.apply
|
|
|
|
...> triangle = Circle.init(Point.init(30, 7), 5)
|
|
|
|
...> |> Circle.to_polygon(3)
|
|
|
|
...> |> Transform.scale(1.5)
|
|
|
|
...> |> Transform.apply
|
|
|
|
...> frame
|
|
|
|
...> |> Frame.push(box, RGBA.black)
|
|
|
|
...> |> Frame.push(circle, RGBA.init(0.5, 0.5, 0.5, 1))
|
|
|
|
...> |> Frame.push(triangle, RGBA.init(0.8, 0.8, 0.8, 1))
|
|
|
|
...> |> to_string
|
|
|
|
"@@@@@@@@@@@@@@@@ :: :::@@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@@ @@@@@ @:@@@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@@ :@@@@@@ @@@::@@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@@ @@@@@ @@@@@@:@@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@:@@ @@ @@@@@@@@@:@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@:@@@@ @@@@@@@@@@:@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@@:@@@@@@@@@@@@@@*@:@@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@:@@@@@@@@@@@@@@@***:@@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@:@@@@@@@@@@@@@@@*@@:*@@@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@:@@@@@@@@@@@@@@@*@@:@**@@@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@:@@@@@@@@@@@@@@@*@@:@@@**@@@@@\n" <>
|
|
|
|
"@@@@@@@@@@:@@@@@@@@@@@@@@@*@@:@@@@@**@@@\n" <>
|
|
|
|
"@@@@@@@@@@@:@@@@@@@@@@@@@@*@:@@@@@@@@*@@\n" <>
|
|
|
|
"@@@@@@@@@@@:@@@@@@@@@@@@@@*@:@@@@@@**@@@\n" <>
|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