This document provides a comprehensive reference for all functions in jon/color-tools
.
valid-hex?
(valid-hex? hex) => boolean
Check if string is a valid hex color.
Parameters:
hex
- String to validateReturns: true
if valid hex color, false
otherwise
Examples:
(valid-hex? "#ff5733") ;=> true
(valid-hex? "#f53") ;=> true
(valid-hex? "ff5733") ;=> true
(valid-hex? "invalid") ;=> false
valid-rgb?
(valid-rgb? rgb) => boolean
Check if vector is a valid RGB color.
Parameters:
rgb
- Vector of [r g b] valuesReturns: true
if valid RGB (all values 0-255), false
otherwise
valid-rgba?
(valid-rgba? rgba) => boolean
Check if vector is a valid RGBA color.
Parameters:
rgba
- Vector of [r g b a] valuesReturns: true
if valid RGBA (RGB 0-255, alpha 0-1), false
otherwise
valid-hsl?
(valid-hsl? hsl) => boolean
Check if vector is a valid HSL color.
Parameters:
hsl
- Vector of [h s l] valuesReturns: true
if valid HSL (h: 0-360, s,l: 0-100), false
otherwise
normalize-hex
(normalize-hex hex) => string
Normalize hex color to 6 characters with #.
Parameters:
hex
- Hex color stringReturns: Normalized 6-character hex string
Examples:
(normalize-hex "#f53") ;=> "#ff5533"
(normalize-hex "ff5733") ;=> "#ff5733"
hex->rgb
(hex->rgb hex) => [r g b]
Convert hex color to RGB vector.
Parameters:
hex
- Valid hex color stringReturns: Vector of [red green blue] values (0-255)
Examples:
(hex->rgb "#ff5733") ;=> [255 87 51]
(hex->rgb "#f53") ;=> [255 85 51]
rgb->hex
(rgb->hex rgb) => string
Convert RGB vector to hex string.
Parameters:
rgb
- Vector of [r g b] values (0-255)Returns: Hex color string
Examples:
(rgb->hex [255 87 51]) ;=> "#ff5733"
hex->rgba
(hex->rgba hex alpha) => [r g b a]
Convert hex color to RGBA vector with specified alpha.
Parameters:
hex
- Valid hex color stringalpha
- Alpha value (0-1)Returns: Vector of [red green blue alpha]
rgba->hex
(rgba->hex rgba) => string
Convert RGBA vector to hex string (ignoring alpha).
Parameters:
rgba
- Vector of [r g b a] valuesReturns: Hex color string
rgb->hsl
(rgb->hsl rgb) => [h s l]
Convert RGB to HSL color space.
Parameters:
rgb
- Vector of [r g b] values (0-255)Returns: Vector of [hue saturation lightness] (h: 0-360, s,l: 0-100)
hsl->rgb
(hsl->rgb hsl) => [r g b]
Convert HSL to RGB color space.
Parameters:
hsl
- Vector of [h s l] valuesReturns: Vector of [red green blue] values (0-255)
hex->hsl
(hex->hsl hex) => [h s l]
Convert hex color to HSL.
Parameters:
hex
- Valid hex color stringReturns: Vector of [hue saturation lightness]
hsl->hex
(hsl->hex hsl) => string
Convert HSL to hex color.
Parameters:
hsl
- Vector of [h s l] valuesReturns: Hex color string
rgb->hsv
(rgb->hsv rgb) => [h s v]
Convert RGB to HSV color space.
hsv->rgb
(hsv->rgb hsv) => [r g b]
Convert HSV to RGB color space.
lighten
(lighten color amount) => color
Lighten a color by a percentage.
Parameters:
color
- Color (hex string or RGB vector)amount
- Amount to lighten (0-1)Returns: Color in same format as input
Examples:
(lighten "#3498db" 0.2) ;=> "#5dade2"
(lighten [52 152 219] 0.2) ;=> [93 173 226]
darken
(darken color amount) => color
Darken a color by a percentage.
Parameters:
color
- Color (hex string or RGB vector)amount
- Amount to darken (0-1)Returns: Color in same format as input
saturate
(saturate color amount) => color
Increase saturation of a color by a percentage.
Parameters:
color
- Color (hex string or RGB vector)amount
- Amount to saturate (0-1)Returns: Color in same format as input
desaturate
(desaturate color amount) => color
Decrease saturation of a color by a percentage.
adjust-hue
(adjust-hue color degrees) => color
Adjust the hue of a color by degrees.
Parameters:
color
- Color (hex string or RGB vector)degrees
- Degrees to shift hue (-360 to 360)Returns: Color in same format as input
invert
(invert color) => color
Invert a color (each RGB component becomes 255 - component).
grayscale
(grayscale color) => color
Convert a color to grayscale using luminance weights.
luminance
(luminance color) => number
Calculate relative luminance of a color (0-1).
Parameters:
color
- Color (hex string or RGB vector)Returns: Relative luminance value (0-1)
contrast-ratio
(contrast-ratio color1 color2) => number
Calculate contrast ratio between two colors.
Parameters:
color1
- First colorcolor2
- Second colorReturns: Contrast ratio (1-21)
Examples:
(contrast-ratio "#000000" "#ffffff") ;=> 21.0
(contrast-ratio "#3498db" "#ffffff") ;=> 3.14
accessible?
(accessible? color1 color2 & [level]) => boolean
Check if two colors meet WCAG accessibility standards.
Parameters:
color1
- First colorcolor2
- Second colorlevel
- Optional accessibility level (:aa
, :aa-large
, :aaa
)Returns: true
if colors meet specified standard
brightness
(brightness color) => number
Calculate perceived brightness of a color (0-255).
dark?
(dark? color) => boolean
Check if a color is dark (brightness < 128).
light?
(light? color) => boolean
Check if a color is light (brightness >= 128).
warm?
(warm? color) => boolean
Check if a color is warm (red/orange/yellow family).
cool?
(cool? color) => boolean
Check if a color is cool (blue/green/purple family).
vibrant?
(vibrant? color & [threshold]) => boolean
Check if a color is vibrant (high saturation).
Parameters:
color
- Color to checkthreshold
- Optional saturation threshold (default 60)muted?
(muted? color & [threshold]) => boolean
Check if a color is muted (low saturation).
complementary
(complementary color) => color
Get the complementary color (opposite on color wheel).
triadic
(triadic color) => [color color]
Get triadic colors (120° and 240° from base).
tetradic
(tetradic color) => [color color color]
Get tetradic colors (90°, 180°, 270° from base).
analogous
(analogous color & [count angle]) => [color ...]
Generate analogous colors.
Parameters:
color
- Base colorcount
- Number of colors to generate (default 3)angle
- Angle between colors in degrees (default 30)monochromatic
(monochromatic color & [count]) => [color ...]
Generate monochromatic palette by varying lightness and saturation.
split-complementary
(split-complementary color & [angle]) => [color color]
Get split-complementary colors.
generate-palette
(generate-palette strategy base-color & [options]) => [color ...]
Generate a color palette using various strategies.
Parameters:
strategy
- Palette strategy (:monochromatic
, :analogous
, :triadic
, etc.)base-color
- Base color for paletteoptions
- Map of options (:count
, :angle
, etc.)mix
(mix color1 color2 & [ratio]) => color
Mix two colors with optional ratio.
Parameters:
color1
- First colorcolor2
- Second colorratio
- Mix ratio (0-1, default 0.5)Returns: Mixed color in same format as first color
color-distance
(color-distance color1 color2) => number
Calculate Euclidean distance between two colors in RGB space.
similar?
(similar? color1 color2 & [threshold]) => boolean
Check if two colors are similar within a threshold.
name->hex
(name->hex color-name) => string
Convert color name to hex.
Examples:
(name->hex "red") ;=> "#ff0000"
(name->hex "navy") ;=> "#000080"
hex->name
(hex->name hex) => string
Find closest color name for a hex color.
random-color
(random-color) => string
Generate a random hex color.
find-accessible-color
(find-accessible-color background target-color & [level]) => color
Find an accessible color by adjusting lightness.
Parameters:
background
- Background colortarget-color
- Desired color to make accessiblelevel
- Accessibility level (:aa
, :aa-large
, :aaa
)Returns: Accessible version of target color, or nil
if none found
clamp
(clamp value min-val max-val) => number
Clamp a value between min and max.
round
(round n & [decimals]) => number
Round a number to specified decimal places.
round-int
(round-int n) => integer
Round a number to the nearest integer.
Can you improve this documentation?Edit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
Ctrl+k | Jump to recent docs |
← | Move to previous article |
→ | Move to next article |
Ctrl+/ | Jump to the search field |