diff --git a/src/glee_gd.gleam b/src/glee_gd.gleam index d30250a..8cab93a 100644 --- a/src/glee_gd.gleam +++ b/src/glee_gd.gleam @@ -1,58 +1,68 @@ -pub type Pid +import glee_gd/egd.{type Color, type Image, type Point, type RGB} -pub type Image = - Pid +pub fn arc(image: Image, p1: Point, p2: Point, color: Color) { + egd.arc(image, p1, p2, color) + image +} -pub type Color = - #(Float, Float, Float, Float) +pub fn arcd(image: Image, p1: Point, p2: Point, d: Int, color: Color) { + egd.arcd(image, p1, p2, d, color) + image +} -pub type RGB = - #(Int, Int, Int) +pub fn color(color: RGB) { + egd.color(color) +} -pub type Point = - #(Int, Int) +pub fn create(width: Int, height: Int) { + egd.create(width, height) +} -@external(erlang, "egd", "arc") -pub fn arc(image: Image, p1: Point, p2: Point, color: Color) -> Nil +pub fn destroy(image: Image) { + egd.destroy(image) +} -@external(erlang, "egd", "arc") -pub fn arcd(image: Image, p1: Point, p2: Point, d: Int, color: Color) -> Nil +pub fn filled_ellipse(image: Image, p1: Point, p2: Point, color: Color) { + egd.filled_ellipse(image, p1, p2, color) + image +} -@external(erlang, "egd", "color") -pub fn color(color: RGB) -> Color +pub fn filled_rectangle(image: Image, p1: Point, p2: Point, color: Color) { + egd.filled_rectangle(image, p1, p2, color) + image +} -@external(erlang, "egd", "create") -pub fn create(width: Int, height: Int) -> Image - -@external(erlang, "egd", "destroy") -pub fn destroy(image: Image) -> Nil - -@external(erlang, "egd", "filledEllipse") -pub fn filled_ellipse(image: Image, p1: Point, p2: Point, color: Color) -> Nil - -@external(erlang, "egd", "filledRectangle") -pub fn filled_rectangle(image: Image, p1: Point, p2: Point, color: Color) -> Nil - -@external(erlang, "egd", "filledTriangle") pub fn filled_triangle( image: Image, p1: Point, p2: Point, p3: Point, color: Color, -) -> Nil - -@external(erlang, "egd", "information") -pub fn information(image: Image) -> Nil - -@external(erlang, "egd", "line") -pub fn line(image: Image, p1: Point, p2: Point, color: Color) -> Nil - -@external(erlang, "egd", "polygon") -pub fn polygon(image: Image, points: List(Point), color: Color) -> Nil - -@external(erlang, "egd", "rectangle") -pub fn rectangle(image: Image, p1: Point, p2: Point, color: Color) -> Nil - -@external(erlang, "egd", "render") -pub fn render(image: Image) -> String +) { + egd.filled_triangle(image, p1, p2, p3, color) + image +} + +pub fn information(image: Image) { + egd.information(image) + image +} + +pub fn line(image: Image, p1: Point, p2: Point, color: Color) { + egd.line(image, p1, p2, color) + image +} + +pub fn polygon(image: Image, points: List(Point), color: Color) { + egd.polygon(image, points, color) + image +} + +pub fn rectangle(image: Image, p1: Point, p2: Point, color: Color) { + egd.rectangle(image, p1, p2, color) + image +} + +pub fn render(image: Image) -> String { + egd.render(image) +} diff --git a/src/glee_gd/egd.gleam b/src/glee_gd/egd.gleam new file mode 100644 index 0000000..d30250a --- /dev/null +++ b/src/glee_gd/egd.gleam @@ -0,0 +1,58 @@ +pub type Pid + +pub type Image = + Pid + +pub type Color = + #(Float, Float, Float, Float) + +pub type RGB = + #(Int, Int, Int) + +pub type Point = + #(Int, Int) + +@external(erlang, "egd", "arc") +pub fn arc(image: Image, p1: Point, p2: Point, color: Color) -> Nil + +@external(erlang, "egd", "arc") +pub fn arcd(image: Image, p1: Point, p2: Point, d: Int, color: Color) -> Nil + +@external(erlang, "egd", "color") +pub fn color(color: RGB) -> Color + +@external(erlang, "egd", "create") +pub fn create(width: Int, height: Int) -> Image + +@external(erlang, "egd", "destroy") +pub fn destroy(image: Image) -> Nil + +@external(erlang, "egd", "filledEllipse") +pub fn filled_ellipse(image: Image, p1: Point, p2: Point, color: Color) -> Nil + +@external(erlang, "egd", "filledRectangle") +pub fn filled_rectangle(image: Image, p1: Point, p2: Point, color: Color) -> Nil + +@external(erlang, "egd", "filledTriangle") +pub fn filled_triangle( + image: Image, + p1: Point, + p2: Point, + p3: Point, + color: Color, +) -> Nil + +@external(erlang, "egd", "information") +pub fn information(image: Image) -> Nil + +@external(erlang, "egd", "line") +pub fn line(image: Image, p1: Point, p2: Point, color: Color) -> Nil + +@external(erlang, "egd", "polygon") +pub fn polygon(image: Image, points: List(Point), color: Color) -> Nil + +@external(erlang, "egd", "rectangle") +pub fn rectangle(image: Image, p1: Point, p2: Point, color: Color) -> Nil + +@external(erlang, "egd", "render") +pub fn render(image: Image) -> String diff --git a/test/glee_gd_test.gleam b/test/glee_gd_test.gleam index 1a8691b..2fc7b76 100644 --- a/test/glee_gd_test.gleam +++ b/test/glee_gd_test.gleam @@ -1,5 +1,5 @@ import gleam/bit_array -import glee_gd +import glee_gd as egd import gleeunit import gleeunit/should import simplifile @@ -9,26 +9,26 @@ pub fn main() { } pub fn render_ellipse_test() { - let image = glee_gd.create(500, 500) - let color = glee_gd.color(#(109, 74, 126)) - glee_gd.filled_ellipse(image, #(100, 400), #(400, 100), color) - glee_gd.render(image) + let color = egd.color(#(109, 74, 126)) + egd.create(500, 500) + |> egd.filled_ellipse(#(100, 400), #(400, 100), color) + |> egd.render |> should_be_fixture("elixir-ellipse") } pub fn render_rectangle_test() { - let image = glee_gd.create(500, 500) - let color = glee_gd.color(#(0, 172, 216)) - glee_gd.filled_rectangle(image, #(100, 400), #(400, 100), color) - glee_gd.render(image) + let color = egd.color(#(0, 172, 216)) + egd.create(500, 500) + |> egd.filled_rectangle(#(100, 400), #(400, 100), color) + |> egd.render |> should_be_fixture("go-rectangle") } pub fn render_triangle_test() { - let image = glee_gd.create(500, 500) - let color = glee_gd.color(#(255, 175, 243)) - glee_gd.filled_triangle(image, #(250, 125), #(100, 375), #(400, 375), color) - glee_gd.render(image) + let color = egd.color(#(255, 175, 243)) + egd.create(500, 500) + |> egd.filled_triangle(#(250, 125), #(100, 375), #(400, 375), color) + |> egd.render |> should_be_fixture("gleam-triangle") }