Tint (Tint v1.1.0) View Source

A library allowing calculations with colors and conversions between different colorspaces.

Link to this section Summary

Types

A type representing a color.

A type representing a colorspace.

Functions

Converts the given color to another colorspace.

Converts the given color to another colorspace. Raises when the colorspace is invalid.

Gets the converted module for the given colorspace atom or module.

Converts the given color to the CMYK colorspace.

Converts the given color to the DIN99 colorspace.

Converts the given color to the HSV colorspace.

Converts the given color to the CIELAB colorspace.

Converts the given color to the RGB colorspace.

Converts the given color to the XYZ (CIE 1931) colorspace.

Link to this section Types

Specs

A type representing a color.

Specs

colorspace() :: atom() | module()

A type representing a colorspace.

Link to this section Functions

Link to this function

convert(color, colorspace)

View Source (since 1.0.0)

Specs

convert(color(), colorspace()) :: {:ok, color()} | :error

Converts the given color to another colorspace.

Examples

iex> Tint.convert(Tint.RGB.new(40, 66, 67), :cmyk)
{:ok, %Tint.CMYK{cyan: 0.403, magenta: 0.0149, yellow: 0.0, key: 0.7373}}

iex> Tint.convert(Tint.RGB.new(255, 127, 30), Tint.HSV)
{:ok, %Tint.HSV{hue: 25.9, saturation: 0.8824, value: 1.0}}

iex> Tint.convert(Tint.RGB.new(255, 127, 30), :invalid)
:error
Link to this function

convert!(color, colorspace)

View Source (since 1.0.0)

Specs

convert!(color(), colorspace()) :: color()

Converts the given color to another colorspace. Raises when the colorspace is invalid.

Examples

iex> Tint.convert!(Tint.RGB.new(40, 66, 67), :cmyk)
%Tint.CMYK{cyan: 0.403, magenta: 0.0149, yellow: 0.0, key: 0.7373}

iex> Tint.convert!(Tint.RGB.new(255, 127, 30), Tint.HSV)
%Tint.HSV{hue: 25.9, saturation: 0.8824, value: 1.0}

iex> Tint.convert!(Tint.RGB.new(255, 127, 30), :foo)
** (ArgumentError) Unknown colorspace: :foo
Link to this function

converter_for(colorspace)

View Source (since 1.0.0)

Specs

converter_for(colorspace()) :: {:ok, module()} | :error

Gets the converted module for the given colorspace atom or module.

Link to this function

to_cmyk(color)

View Source (since 0.3.0)

Specs

to_cmyk(color()) :: Tint.CMYK.t()

Converts the given color to the CMYK colorspace.

Example

iex> Tint.to_cmyk(Tint.RGB.new(40, 66, 67))
#Tint.CMYK<40.3%,1.49%,0.0%,73.73%>
Link to this function

to_din99(color)

View Source (since 1.0.0)

Specs

to_din99(color()) :: Tint.DIN99.t()

Converts the given color to the DIN99 colorspace.

Specs

to_hsv(color()) :: Tint.HSV.t()

Converts the given color to the HSV colorspace.

Example

iex> Tint.to_hsv(Tint.RGB.new(255, 127, 30))
#Tint.HSV<25.9°,88.24%,100.0%>
Link to this function

to_lab(color)

View Source (since 1.0.0)

Specs

to_lab(color()) :: Tint.Lab.t()

Converts the given color to the CIELAB colorspace.

Specs

to_rgb(color()) :: Tint.RGB.t()

Converts the given color to the RGB colorspace.

Example

iex> Tint.to_rgb(Tint.HSV.new(25.8, 0.882, 1))
#Tint.RGB<255,127,30 (#FF7F1E)>
Link to this function

to_xyz(color)

View Source (since 1.0.0)

Specs

to_xyz(color()) :: Tint.XYZ.t()

Converts the given color to the XYZ (CIE 1931) colorspace.