Color manipulation and conversion utilities for the shared Color type.
Use these functions to create, transform, and convert colors in various formats, then use them in animations.
Use these functions to create colors.
Create a hex color from a string.
hex "#ff0000" -- Red
hex "#f00" -- Red (shorthand)
hex "ff0000" -- Red (without #)Invalid hex strings will return Nothing.
Create an RGB color from individual components.
rgb 255 0 0 -- RedCreate an RGBA color from individual components.
rgba 255 0 0 0.5 -- Semi-transparent redCreate an HSL color from individual components.
h (hue): 0-360 degreess (saturation): 0-100 percentl (lightness): 0-100 percenthsl 0 100 50 -- RedCreate an HSLA color from individual components.
h (hue): 0-360 degreess (saturation): 0-100 percentl (lightness): 0-100 percenta (alpha): 0-1hsla 0 100 50 0.5 -- Semi-transparent redCreate a color from a hex string.
fromHex "#ff0000" -- Just Red
fromHex "#f00" -- Just Red (shorthand)
fromHex "invalid" -- NothingInvalid hex strings will return Nothing.
Convert a Color to a hex string .
Create a Color from RGB components.
fromRgb { r = 255, g = 0, b = 0 } -- RedCreate a Color from RGBA components.
fromRgba { r = 255, g = 0, b = 0, a = 0.5 } -- Semi-transparent redConvert a Color to an RGB color record.
Convert a Color to an RGBA color record.
Create a Color from HSL components.
h (hue): 0-360 degreess (saturation): 0-100 percentl (lightness): 0-100 percentfromHsl { h = 0, s = 100, l = 50 } -- RedCreate a Color from HSLA components.
h (hue): 0-360 degreess (saturation): 0-100 percentl (lightness): 0-100 percenta (alpha): 0-1fromHsla { h = 0, s = 100, l = 50, a = 0.5 } -- Semi-transparent redConvert a Color to an HSL color record.
Convert a Color to an HSLA color record.
Use colors from the avh4/elm-color package.
Parse a color from various string formats.
Supports:
Hex: "#ff0000", "#f00", "ff0000", "f00"
RGB: "rgb(255, 0, 0)"
RGBA: "rgba(255, 0, 0, 0.5)"
HSL: "hsl(0, 100%, 50%)"
HSLA: "hsla(0, 100%, 50%, 0.5)"
fromString "#ff0000" -- Just red
fromString "rgb(255, 0, 0)" -- Just red
fromString "invalid" -- NothingSet the alpha (transparency) value of a color.
-- Semi-transparent red
setAlpha 0.5 <|
fromRgb { r = 255, g = 0, b = 0 }Increase the lightness of a color.
brighten 0.2 <|
fromRgb { r = 100, g = 100, b = 100 } -- Lighter grayDecrease the lightness of a color.
darken 0.2 <|
fromRgb { r = 100, g = 100, b = 100 } -- Darker grayIncrease the saturation of a color.
saturate 0.2 <|
fromHsl {h = 0, s = 50, l = 50} -- More saturated redDecrease the saturation of a color.
desaturate 0.2 <|
fromHsl {h = 0, s = 50, l = 50} -- Less saturated redFully transparent white.
Color used in animations.