Update typespecs and docs.
This commit is contained in:
parent
233532544c
commit
3030368b8e
7 changed files with 46 additions and 20 deletions
21
README.md
21
README.md
|
@ -22,3 +22,24 @@ is included in the `LICENSE` file in this distribution.
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Documentations can be found at [https://hexdocs.pm/vivid_png](https://hexdocs.pm/vivid_png).
|
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")
|
||||||
|
```
|
BIN
example.png
Normal file
BIN
example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
|
@ -1,7 +1,14 @@
|
||||||
defimpl Vivid.PNG, for: Vivid.Buffer do
|
defimpl Vivid.PNG, for: Vivid.Buffer do
|
||||||
alias Vivid.PNG.Palette
|
|
||||||
alias Vivid.{Buffer, RGBA}
|
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
|
def to_png(buffer, path) do
|
||||||
with {:ok, file} <- File.open(path, [:write]),
|
with {:ok, file} <- File.open(path, [:write]),
|
||||||
png <- create_png(buffer, file),
|
png <- create_png(buffer, file),
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
defimpl Vivid.PNG, for: Vivid.Frame do
|
defimpl Vivid.PNG, for: Vivid.Frame do
|
||||||
alias Vivid.{PNG, Frame}
|
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
|
def to_png(frame, file) do
|
||||||
frame
|
frame
|
||||||
|> Frame.buffer(:horizontal)
|
|> Frame.buffer(:horizontal)
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
defmodule Vivid.PNG.ShapeToPng do
|
defmodule Vivid.PNG.ShapeToPng do
|
||||||
use Vivid
|
alias Vivid.{PNG, Shape, Bounds, Transform, Frame}
|
||||||
alias Vivid.PNG
|
|
||||||
|
|
||||||
|
@moduledoc false
|
||||||
|
|
||||||
|
@doc false
|
||||||
|
@spec to_png(Shape.t, Path.t) :: :ok | {:error, any}
|
||||||
def to_png(shape, file) do
|
def to_png(shape, file) do
|
||||||
bounds = Bounds.bounds(shape)
|
bounds = Bounds.bounds(shape)
|
||||||
width = bounds |> Bounds.width |> round |> Kernel.+(3)
|
width = bounds |> Bounds.width |> round |> Kernel.+(3)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
defprotocol Vivid.PNG do
|
defprotocol Vivid.PNG do
|
||||||
alias Vivid.Shape
|
alias Vivid.{Shape, Frame, Buffer}
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
Turn a Vivid frame or shape into a PNG
|
Turn a Vivid frame or shape into a PNG
|
||||||
"""
|
"""
|
||||||
|
@ -7,6 +7,6 @@ defprotocol Vivid.PNG do
|
||||||
@doc """
|
@doc """
|
||||||
Turn a frame or shape into a PNG file.
|
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)
|
def to_png(shape, file)
|
||||||
end
|
end
|
||||||
|
|
17
mix.exs
17
mix.exs
|
@ -12,12 +12,8 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
deps: deps()]
|
deps: deps()]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Configuration for the OTP application
|
|
||||||
#
|
|
||||||
# Type "mix help compile.app" for more information
|
|
||||||
def application do
|
def application do
|
||||||
# Specify extra applications you'll use from Erlang/Elixir
|
[applications: [:logger, :png]]
|
||||||
[extra_applications: [:logger, :png]]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def description do
|
def description do
|
||||||
|
@ -28,7 +24,7 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
|
|
||||||
def package do
|
def package do
|
||||||
[
|
[
|
||||||
maintainers: [ "James Harton <james@messagerocket.co>" ],
|
maintainers: [ "James Harton <james@automat.nz>" ],
|
||||||
licenses: [ "MIT" ],
|
licenses: [ "MIT" ],
|
||||||
links: %{
|
links: %{
|
||||||
"Source" => "https://github.com/jamesotron/vivid_png.ex"
|
"Source" => "https://github.com/jamesotron/vivid_png.ex"
|
||||||
|
@ -36,15 +32,6 @@ defmodule Vivid.PNG.Mixfile do
|
||||||
]
|
]
|
||||||
end
|
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
|
defp deps do
|
||||||
[
|
[
|
||||||
{:ex_doc, ">= 0.0.0", only: :dev},
|
{:ex_doc, ">= 0.0.0", only: :dev},
|
||||||
|
|
Loading…
Reference in a new issue