vivid v0.4.1 Vivid.RGBA

Defines a colour in RGBA colour space.

Colour and alpha values are defined as 0 >= n >= 1.

Summary

Functions

Return the alpha component of the colour

Shorthand for black

Return the blue component of the colour

Return the green component of the colour

Create a colour. Like magic

Create a colour. Like magic

Return the luminance of a colour, using some colour mixing ratios I found on stack exchange

Blend two colours together using their alpha information using the “over” algorithm

Return the red component of the colour

Convert a colour to an ASCII character

Convert a colour to HTML style hex

Shorthand for white

Types

t()
t
zero_to_one()
zero_to_one() :: number

Functions

alpha(r_g_b_a)

Return the alpha component of the colour.

Example

iex> Vivid.RGBA.init(0.7, 0.6, 0.5, 0.4)
...> |> Vivid.RGBA.alpha
0.4
black()
black() :: Vivid.RGBA.t

Shorthand for black.

Example

iex> Vivid.RGBA.black
#Vivid.RGBA<{0, 0, 0, 1}>
blue(r_g_b_a)

Return the blue component of the colour.

Example

iex> Vivid.RGBA.init(0.7, 0.6, 0.5, 0.4)
...> |> Vivid.RGBA.blue
0.5
green(r_g_b_a)

Return the green component of the colour.

Example

iex> Vivid.RGBA.init(0.7, 0.6, 0.5, 0.4)
...> |> Vivid.RGBA.green
0.6
init(red, green, blue)

Create a colour. Like magic.

  • red the red component of the colour.
  • green the green component of the colour.
  • blue the blue component of the colour.

All values are between zero and one.

When the alpha argument is omitted it is assumed to be 1.

Example

iex> Vivid.RGBA.init(0.1, 0.2, 0.3, 0.4)
#Vivid.RGBA<{0.1, 0.2, 0.3, 0.4}>
init(red, green, blue, alpha)

Create a colour. Like magic.

  • red the red component of the colour.
  • green the green component of the colour.
  • blue the blue component of the colour.
  • alpha the opacity of the colour.

All values are between zero and one.

Example

iex> Vivid.RGBA.init(0.1, 0.2, 0.3, 0.4)
#Vivid.RGBA<{0.1, 0.2, 0.3, 0.4}>
luminance(r_g_b_a)
luminance(Vivid.RGBA.t) :: zero_to_one

Return the luminance of a colour, using some colour mixing ratios I found on stack exchange.

Examples

iex> Vivid.RGBA.init(1,0,0) |> Vivid.RGBA.luminance
0.2128

iex> Vivid.RGBA.white |> Vivid.RGBA.luminance
1.0

iex> Vivid.RGBA.black |> Vivid.RGBA.luminance
0.0
over(visible, colour)

Blend two colours together using their alpha information using the “over” algorithm.

Examples

iex> Vivid.RGBA.over(Vivid.RGBA.black, Vivid.RGBA.init(1,1,1, 0.5))
#Vivid.RGBA<{0.5, 0.5, 0.5, 1.0}>
red(r_g_b_a)

Return the red component of the colour.

Example

iex> Vivid.RGBA.init(0.7, 0.6, 0.5, 0.4)
...> |> Vivid.RGBA.red
0.7
to_ascii(colour)
to_ascii(Vivid.RGBA.t) :: String.t

Convert a colour to an ASCII character.

This isn’t very scientific, but helps with debugging and is used in the implementations of String.Chars for Vivid types.

The chacaters used (from black to white) are " .:-=+*#%@". These are chosen based on the luminance/1 value of the colour.

to_hex(r_g_b_a)
to_hex(Vivid.RGBA.t) :: String.t

Convert a colour to HTML style hex.

Example

iex> Vivid.RGBA.init(0.7, 0.6, 0.5)
...> |> Vivid.RGBA.to_hex
"#B39980"
white()
white() :: Vivid.RGBA.t

Shorthand for white.

Example

iex> Vivid.RGBA.white
#Vivid.RGBA<{1, 1, 1, 1}>