elm-athlete/athlete/2.3.0

NOTE: the latest version is 7.0.0

Color

Library for working with colors. Includes RGB and HSL creation, gradients, and built-in names.

Colors

type Color

Representation of colors.

Creation

rgb : Int -> Int -> Int -> Color

Create RGB colors from numbers between 0 and 255 inclusive.

rgba : Int -> Int -> Int -> Float -> Color

Create RGB colors with an alpha component for transparency. The alpha component is specified with numbers between 0 and 1.

hsl : Float -> Float -> Float -> Color

Create HSL colors. This gives you access to colors more like a color wheel, where all hues are arranged in a circle that you specify with standard Elm angles (radians).

red =
    hsl (degrees 0) 1 0.5


green =
    hsl (degrees 120) 1 0.5


blue =
    hsl (degrees 240) 1 0.5


pastelRed =
    hsl (degrees 0) 0.7 0.7

To cycle through all colors, just cycle through degrees. The saturation level is how vibrant the color is, like a dial between grey and bright colors. The lightness level is a dial between white and black.

hsla : Float -> Float -> Float -> Float -> Color

Create HSL colors with an alpha component for transparency.

greyscale : Float -> Color

Produce a gray based on the input. 0 is white, 1 is black.

grayscale : Float -> Color

Produce a gray based on the input. 0 is white, 1 is black.

Produce a “complementary color”. The two colors will accent each other. This is the same as rotating the hue by 180°.

Gradients

Abstract representation of a color gradient.

( Float, Float )
-> ( Float, Float )
-> List ( Float, Color )

Create a linear gradient. Takes a start and end point and then a series of “color stops” that indicate how to interpolate between the start and end points. See this example for a more visual explanation.

( Float, Float )
-> Float
-> ( Float, Float )
-> Float
-> List ( Float, Color )

Create a radial gradient. First takes a start point and inner radius. Then takes an end point and outer radius. It then takes a series of “color stops” that indicate how to interpolate between the inner and outer circles. See this example for a more visual explanation.

Extracting Colors

-> { red : Int
, green : Int
, blue : Int
, alpha : Float
}

Extract the components of a color in the RGB format.

-> { hue : Float
, saturation : Float
, lightness : Float
, alpha : Float
}

Extract the components of a color in the HSL format.

Built-in Colors

These colors come from the Tango palette which provides aesthetically reasonable defaults for colors. Each color also comes with a light and dark version.

Standard

Light

Dark

Eight Shades of Grey

These colors are a compatible series of shades of grey, fitting nicely with the Tango palette.

These are identical to the grey versions. It seems the spelling is regional, but that has never helped me remember which one I should be writing.