Tint

Build Status Coverage Status Hex.pm

An Elixir library allowing calculations with colors and conversions between different colorspaces.

Currently supports the RGB, CMYK and HSV color models.

Prerequisites

  • Elixir 1.7 or greater

Installation

The package can be installed by adding tint to your list of dependencies in mix.exs:

def deps do
  [
    {:tint, "~> 0.3"}
  ]
end

Usage

RGB

iex> Tint.RGB.new(255, 0, 0)
#Tint.RGB<255,0,0>

CMYK

iex> Tint.CMYK.new(0.55, 0.26, 0.24, 0.65)
#Tint.CMYK<55%,26%,24%,65%>

HSV

iex> Tint.HSV.new(25.8, 0.882, 1)
#Tint.HSV<25.8°,88.2%,100%>

Conversion

Between Colorspaces

iex> rgb = Tint.RGB.new(255, 0, 0)
...> Tint.to_hsv(rgb)
#Tint.HSV<0°,100%,100%>

Hex Code

iex> Tint.RGB.from_hex("#FF0000")
{:ok, #Tint.RGB<255,0,0>}
iex> Tint.RGB.from_hex("invalid hex code")
:error
iex> Tint.RGB.to_hex(Tint.RGB.new(255, 0, 0))
"#FF0000"

Docs

The API docs can be found at HexDocs.