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
Functions
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
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
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
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(zero_to_one, zero_to_one, zero_to_one, zero_to_one) :: Vivid.RGBA.t
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}>
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
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}>
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
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.
Convert a colour to HTML style hex.
Example
iex> Vivid.RGBA.init(0.7, 0.6, 0.5)
...> |> Vivid.RGBA.to_hex
"#B39980"