From 3030368b8e3cf3285416eb80799e36cad480bf93 Mon Sep 17 00:00:00 2001 From: James Harton Date: Thu, 12 Jan 2017 08:55:58 +1300 Subject: [PATCH] Update typespecs and docs. --- README.md | 21 +++++++++++++++++++++ example.png | Bin 0 -> 1601 bytes lib/vivid/png/buffer.ex | 9 ++++++++- lib/vivid/png/frame.ex | 8 ++++++++ lib/vivid/png/shape.ex | 7 +++++-- lib/vivid_png.ex | 4 ++-- mix.exs | 17 ++--------------- 7 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 example.png diff --git a/README.md b/README.md index 8acd3ab..fdafe2f 100644 --- a/README.md +++ b/README.md @@ -22,3 +22,24 @@ is included in the `LICENSE` file in this distribution. ## Documentation Documentations can be found at [https://hexdocs.pm/vivid_png](https://hexdocs.pm/vivid_png). + +## Status + +```elixir +use Vivid +alias Vivid.PNG + +frame = Frame.init(300,200) +text = Font.line("seems to work") + |> Transform.fill(frame) + |> Transform.center(frame) + |> Transform.apply +circle = Circle.init(Point.init(100, 100), 50) +box = Box.init(Point.init(250,150), Point.init(275, 175)) + +frame +|> Frame.push(text, RGBA.black) +|> Frame.push(circle, RGBA.init(1,0,0,0.5)) +|> Frame.push(box, RGBA.init(0,0,1, 0.75)) +|> PNG.to_png("example.png") +``` \ No newline at end of file diff --git a/example.png b/example.png new file mode 100644 index 0000000000000000000000000000000000000000..3625ee84f51f2df282707d9a98d9e844629d0054 GIT binary patch literal 1601 zcmb_cS5y-Q6paC84;e(;K5lRVFB+RHOTPRd^2_UCH4XZ?j zm;@4_qU^|$vO**z61E^CVH!gY1VgbOZGSxd>HB#1zVqJwdFR}l<>l$BB(E(G005NS zF2KA2fJ3GSyifMXLHC}S^Z@{l$hyJKU5PDSoASFmVXJz0#Ps93=|w?z`PMIM$g^@^ zf0OK3O{hqXwI1gbco**N9zIZhwl1xTHZ0APyIfMU=sH9`o3BV@WM)4DHkq6$Ve@-#;a)l$uLi!W)R1rABzF8%wG8=iV^2 zsQYz<73Hkmm$uB?8L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Zi6c&<%KW}#z| zv2Z9KzAdL%ASb1-zApFcg;TOwTH65Auk@VKpWH~!@s)Y;P$SL#ApS}gN@8660_I~B fJ{!#cxnS+cqzdG8UO!~UeY$mnd%|kZqkj4mGq?Uz literal 0 HcmV?d00001 diff --git a/lib/vivid/png/buffer.ex b/lib/vivid/png/buffer.ex index c115447..aabcef4 100644 --- a/lib/vivid/png/buffer.ex +++ b/lib/vivid/png/buffer.ex @@ -1,7 +1,14 @@ defimpl Vivid.PNG, for: Vivid.Buffer do - alias Vivid.PNG.Palette alias Vivid.{Buffer, RGBA} + @moduledoc """ + Convert a Vivid buffer to a PNG file. + """ + + @doc """ + Convert a Vivid buffer into a PNG file. + """ + @spec to_png(Buffer.t, Path.t) :: :ok | {:error, any} def to_png(buffer, path) do with {:ok, file} <- File.open(path, [:write]), png <- create_png(buffer, file), diff --git a/lib/vivid/png/frame.ex b/lib/vivid/png/frame.ex index 6fed81d..b1a00b4 100644 --- a/lib/vivid/png/frame.ex +++ b/lib/vivid/png/frame.ex @@ -1,6 +1,14 @@ defimpl Vivid.PNG, for: Vivid.Frame do alias Vivid.{PNG, Frame} + @moduledoc """ + Convert a Vivid frame into a PNG file. + """ + + @doc """ + Convert a Vivid frame into a PNG file. + """ + @spec to_png(Frame.t, Path.t) :: :ok | {:error, any} def to_png(frame, file) do frame |> Frame.buffer(:horizontal) diff --git a/lib/vivid/png/shape.ex b/lib/vivid/png/shape.ex index d1c6296..5be1eed 100644 --- a/lib/vivid/png/shape.ex +++ b/lib/vivid/png/shape.ex @@ -1,7 +1,10 @@ defmodule Vivid.PNG.ShapeToPng do - use Vivid - alias Vivid.PNG + alias Vivid.{PNG, Shape, Bounds, Transform, Frame} + @moduledoc false + + @doc false + @spec to_png(Shape.t, Path.t) :: :ok | {:error, any} def to_png(shape, file) do bounds = Bounds.bounds(shape) width = bounds |> Bounds.width |> round |> Kernel.+(3) diff --git a/lib/vivid_png.ex b/lib/vivid_png.ex index 20f4445..45fde85 100644 --- a/lib/vivid_png.ex +++ b/lib/vivid_png.ex @@ -1,5 +1,5 @@ defprotocol Vivid.PNG do - alias Vivid.Shape + alias Vivid.{Shape, Frame, Buffer} @moduledoc """ Turn a Vivid frame or shape into a PNG """ @@ -7,6 +7,6 @@ defprotocol Vivid.PNG do @doc """ Turn a frame or shape into a PNG file. """ - @spec to_png(Shape.t, Path.t) :: :ok | {:error, any} + @spec to_png(Shape.t | Frame.t | Buffer.t, Path.t) :: :ok | {:error, any} def to_png(shape, file) end diff --git a/mix.exs b/mix.exs index 69b2ff9..df08fbb 100644 --- a/mix.exs +++ b/mix.exs @@ -12,12 +12,8 @@ defmodule Vivid.PNG.Mixfile do deps: deps()] end - # Configuration for the OTP application - # - # Type "mix help compile.app" for more information def application do - # Specify extra applications you'll use from Erlang/Elixir - [extra_applications: [:logger, :png]] + [applications: [:logger, :png]] end def description do @@ -28,7 +24,7 @@ defmodule Vivid.PNG.Mixfile do def package do [ - maintainers: [ "James Harton " ], + maintainers: [ "James Harton " ], licenses: [ "MIT" ], links: %{ "Source" => "https://github.com/jamesotron/vivid_png.ex" @@ -36,15 +32,6 @@ defmodule Vivid.PNG.Mixfile do ] end - # Dependencies can be Hex packages: - # - # {:my_dep, "~> 0.3.0"} - # - # Or git/path repositories: - # - # {:my_dep, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - # - # Type "mix help deps" for more examples and options defp deps do [ {:ex_doc, ">= 0.0.0", only: :dev},