luisgabrielroldan / cairo_ex

Elixir wrapper for Cairo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CairoEx

Actions Status Hex version

Cairo wrapper for Elixir.

(THIS IS WORK IN PROGRESS)

Usage

  {:ok, cairo} = CairoEx.start_link()

  {:ok, surface} = Surface.image_surface_create(cairo, :rgb24, 270, 270)
  {:ok, context} = Context.create(surface)

  context
  |> Context.set_source_rgb(1.0, 1.0, 1.0)
  |> Context.paint()
  |> Context.set_source_rgb(0.5, 0.5, 1)
  |> Context.rectangle(20, 20, 100, 100)
  |> Context.fill()
  |> Context.set_source_rgb(0.6, 0.6, 0.6)
  |> Context.rectangle(150, 20, 100, 100)
  |> Context.fill()
  |> Context.set_source_rgb(0, 0.3, 0)
  |> Context.rectangle(20, 140, 100, 100)
  |> Context.fill()
  |> Context.set_source_rgb(1, 0, 0.5)
  |> Context.rectangle(150, 140, 100, 100)
  |> Context.fill()

  :ok = Surface.write_to_png(surface, "/tmp/output.png")
  :ok = Surface.destroy(surface)

Output:

Result image

Installation

If available in Hex, the package can be installed by adding cairo_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:cairo_ex, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/cairo_ex.

About

Elixir wrapper for Cairo

License:Apache License 2.0


Languages

Language:C 63.2%Language:Elixir 34.9%Language:Makefile 1.9%