clojure2d.color
Color functions.
This namespace contains color manipulation functions which can be divided into following groups:
- Color creators
- Channel manipulations
- Conversions
- Palettes / gradients
- Distances
Representation
Color can be represented by following types:
- fastmath
Vec4
- this is core type representing 3 color channels and alpha (RGBA). Values aredouble
type from[0-255]
range. color, gray creators returnsVec4
representation. - fastmath
Vec3
- 3 channels (RGB), assumingalpha
set to value of255
. - fastmath
Vec2
- gray with alpha java.awt.Color
- Java AWT representation. Creators are awt-color, awt-gray. Use to-awt-color to convert to this representation.keyword
- one of the defined names (see named-colors-list)Integer
- packed ARGB value. If value is less than0xff000000
, alpha is set to0xff
. Example:0xffaa01
.String
- CSS (#rgb
or#rgba
) or string containg hexadecimal representation (“ffaa01”)- any
seqable
- list, vector containing 2-4 elements. Conversion is done by applying content to color function.
To create color from individual channel values use color function. To create gray for given intensity call gray.
By default color is treated as RGB
with values from ranges [0.0-255.0]
inclusive.
All funtions internally convert any color representation to Vec4
type using to-color function..
Color/ channel manipulations
You can access individual channels by calling on of the following:
- red or ch0 - to get first channel value.
- green or ch1 - to get second channel value.
- blue or ch2 - to get third channel value.
- alpha - to get alpha value.
- luma - to get luma or brightness (range from
0
(black) to255
(white)). - hue - to get hue value in degrees (range from 0 to 360). Hexagon projection.
- hue-polar - to get hue from polar transformation.
set-ch0, set-ch1, set-ch2 and set-alpha return new color with respective channel set to new value.
General set-channel and get-channel can work with any colorspace.
To make color darker/brighter use darken / lighten functions. Operations are done in Lab
color space.
To change saturation call saturate / desaturate. Operations are done in LCH
color space.
You can also modulate color (ie. multiply by given value).
Conversions
Color can be converted from RGB to other color space (and back). List of color spaces are listed under colorspaces-list variable. There are two types of conversions:
- raw - with names
to-XXX
andfrom-XXX
whereXXX
is color space name. Every color space has it’s own value range for each channel.(comp from-XXX to-XXX)
acts almost as identity. - normalized - with names
to-XXX*
andfrom-XXX*
whereXXX
is color space name.to-XXX*
returns values normalized to[0-255]
range.from-XXX*
expects also channel values in range[0-255]
.
NOTE: there is no information which color space is used. It’s just a matter of your interpretation.
NOTE 2: be aware that converting function do not clamp any values to/from expected range.
Color space conversion functions are collected in two maps colorspaces for raw and colorspaces* for normalized functions. Keys are color space names as keyword
and values are vectors with to-
fn as first and from-
fn as second element.
Palettes / gradients
Links
List of all defined colors and palettes:
Palette
Palette is just sequence of colors.
There are plenty of them predefined or can be generated:
- palette to access palette by keyword (from presets), by number (from colourlovers). Use palette to resample palette or convert gradient to palette.
- paletton-palette function to generate palette of type:
:monochromatic
,:triad
,:tetrad
with complementary color for given hue and configuration. See also Paletton website for details.
Call palette without any parameters to get list of predefined gradients.
Gradient
Gradient is continuous functions which accepts value from [0-1]
range and returns color. Call gradient to create one.
Call gradient without any parameters to obtain list of predefined gradients.
Use gradient to convert any palette to gradient or access predefined gradients by keyword.
Conversions
To convert palette to gradient call gradient function. You can set interpolation method and colorspace. To convert gradient to palette call palette function.
Call palette to resample palette to other number of colors. Internally input palette is converted to gradient and sampled back.
Use lerp, lerp+, mix, average, mixbox to mix two colors in different ways.
Distances
Several functions to calculate difference between colors, delta-E*-xxx
etc.
References
Categories
- Color conversions: color-converter colorspaces colorspaces* colorspaces-list from-CMY from-CMY* from-Cubehelix from-Cubehelix* from-DIN99 from-DIN99* from-DIN99b from-DIN99b* from-DIN99c from-DIN99c* from-DIN99d from-DIN99d* from-DIN99o from-DIN99o* from-GLHS from-GLHS* from-Gray from-Gray* from-HCL from-HCL* from-HSB from-HSB* from-HSI from-HSI* from-HSL from-HSL* from-HSV from-HSV* from-HWB from-HWB* from-HunterLAB from-HunterLAB* from-IPT from-IPT* from-IgPgTg from-IgPgTg* from-JAB from-JAB* from-JCH from-JCH* from-LAB from-LAB* from-LCH from-LCH* from-LCHuv from-LCHuv* from-LMS from-LMS* from-LUV from-LUV* from-OHTA from-OHTA* from-OSA from-OSA* from-RGB from-RGB* from-RYB* from-UCS from-UCS* from-UVW* from-XYZ from-XYZ* from-XYZ1 from-XYZ1* from-YCbCr from-YCbCr* from-YCgCo from-YCgCo* from-YDbDr from-YDbDr* from-YIQ from-YIQ* from-YPbPr from-YPbPr* from-YUV from-YUV* from-Yxy from-Yxy* from-linear from-linearRGB from-linearRGB* from-sRGB from-sRGB* to-CMY to-CMY* to-Cubehelix to-Cubehelix* to-DIN99 to-DIN99* to-DIN99b to-DIN99b* to-DIN99c to-DIN99c* to-DIN99d to-DIN99d* to-DIN99o to-DIN99o* to-GLHS to-GLHS* to-Gray to-Gray* to-HCL to-HCL* to-HSB to-HSB* to-HSI to-HSI* to-HSL to-HSL* to-HSV to-HSV* to-HWB to-HWB* to-HunterLAB to-HunterLAB* to-IPT to-IPT* to-IgPgTg to-IgPgTg* to-JAB to-JAB* to-JCH to-JCH* to-LAB to-LAB* to-LCH to-LCH* to-LCHuv to-LCHuv* to-LMS to-LMS* to-LUV to-LUV* to-OHTA to-OHTA* to-OSA to-OSA* to-Okhsv to-RGB to-RGB* to-RYB* to-UCS to-UCS* to-UVW* to-XYZ to-XYZ* to-XYZ1 to-XYZ1* to-YCbCr to-YCbCr* to-YCgCo to-YCgCo* to-YDbDr to-YDbDr* to-YIQ to-YIQ* to-YPbPr to-YPbPr* to-YUV to-YUV* to-Yxy to-Yxy* to-linear to-linearRGB to-linearRGB* to-sRGB to-sRGB*
- Distance: contrast-ratio delta-C* delta-E*-94 delta-E*-CMC delta-E-z delta-H* delta-e-cie nearest-color noticable-different?
- Gradients: correct-luma gradient gradient-cubehelix iq-gradient merge-gradients random-palette
- Interpolation: average lerp lerp- mix mixsub weighted-average
- Color/channel operations: adjust adjust-temperature alpha awt-color awt-gray blacken blue brighten ch0 ch1 ch2 clamp color darken desaturate format-hex get-channel gray green hue hue-paletton hue-polar lclamp luma modulate pack quil red relative-luma saturate scale scale-down scale-up set-alpha set-awt-alpha set-blue set-ch0 set-ch1 set-ch2 set-channel set-green set-red to-awt-color to-color whiten
- Colors, palettes: correct-luma named-colors-list palette paletton paletton-presets-list possible-color? possible-palette? random-color random-gradient reduce-colors resample temperature tinter valid-color?
Other vars: ->OSAFDF achromatomaly achromatopsia apply-theme black? brightness color-themes complementary contrast delta-C-RGB delta-D-HCL delta-E* delta-E*-2000 delta-E*-euclidean delta-E-HyAB delta-c delta-e-cmc delta-e-jab delta-h deuteranomaly deuteranopia exposure fe-color-matrix find-gradient find-palette from-Okhsl from-Okhsl* from-Okhsv from-Okhsv* from-Okhwb from-Okhwb* from-Oklab from-Oklab* from-Oklch from-Oklch* from-PalettonHSV from-PalettonHSV* from-RYB from-UVW from-XYB from-XYB* from-luma-color-hue grayscale hue-rotate lerp+ make-LCH mixbox negate not-black? protanomaly protanopia saturation sepia temperature-names thing-presets-list to-Okhsl to-Okhsl* to-Okhsv* to-Okhwb to-Okhwb* to-Oklab to-Oklab* to-Oklch to-Oklch* to-PalettonHSV to-PalettonHSV* to-RYB to-UVW to-XYB to-XYB* to-luma-color-hue tritanomaly tritanopia wavelength
Code snippets
Compose two cockatoo images (one is rotated) with given blend method.
(defn blend-images
[f params & opts]
(let [n (str "images/color/" (first opts) ".jpg")]
(c2d/save (p/compose-channels f false i1 i2) (str "docs/" n))
(str "../" n)))
adjust
(adjust col colorspace channel value)
(adjust col channel value)
Adjust (add) given value to a chosen channel. Works with any color space.
adjust-temperature
(adjust-temperature c temp)
(adjust-temperature c temp amount)
Examples
Without adjustment
(palette 0)
Cool
(mapv (fn* [p1__25403#] (adjust-temperature p1__25403# :cool 0.5))
(palette 0))
Warm
(mapv (fn* [p1__25404#] (adjust-temperature p1__25404# :warm 0.5))
(palette 0))
Without adjustment
(gradient [:white :black])
Cold
(comp (fn* [p1__25405#] (adjust-temperature p1__25405# 10000))
(gradient [:white :black]))
Hot
(comp (fn* [p1__25406#] (adjust-temperature p1__25406# 1000))
(gradient [:white :black]))
Adjust color
(adjust-temperature :red 30000)
[#ff8b98] #vec4 [300.96823381696873, 138.67167493994484, 152.3255750376689, 255.0]
alpha
(alpha c)
Returns alpha value.
Examples
Usage
(alpha 85271861)
;;=> 5.0
(alpha :khaki)
;;=> 255.0
apply-theme
(apply-theme color color-theme)
Apply theme to the color, see color-themes for names.
Generates random color similar to provided one. All operations are done in LSH* color space (normalized to have values between 0 and 255).
Color theme can be one of:
- keyword - predefined color theme is used
- L C H - randomization scheme of given channel, which can be:
- min-value max-value - uniform random value from given range
- a number - channel-value, channel+value range is used for random selection
- nil, or anything else - keep original channel value
average
(average cs colorspace)
(average cs)
Average colors in given colorspace
(default: :sRGB
)
Examples
Average in RGB
(average [:yellow :red :teal "#dddddd"])
[#b79757] #vec4 [182.75, 151.0, 87.25, 255.0]
Average in LAB
(average [:yellow :red :teal "#dddddd"] :LAB)
[#d3a96a] #vec4 [210.61859591186501, 168.97690969943264, 105.63239334800473, 255.0]
Average in HSL
(average [:yellow :red :teal "#dddddd"] :LCH)
[#d5aa41] #vec4 [213.2268689301321, 169.67185072866008, 65.36869280587734, 255.0]
awt-color
(awt-color c)
(awt-color c a)
(awt-color r g b)
(awt-color r g b a)
Examples
Usage
(awt-color :yellow)
;;=> java.awt.Color[r=255,g=255,b=0]
(awt-color 6 5 4 11)
;;=> java.awt.Color[r=6,g=5,b=4]
Usage
(awt-color 200 200 112 200)
[#c8c870c8] java.awt.Color[r=200,g=200,b=112]
awt-gray
(awt-gray v)
(awt-gray v a)
Examples
Usage
(awt-gray 23)
[#171717] java.awt.Color[r=23,g=23,b=23]
blacken
(blacken col)
(blacken col amt)
Change color towards black.
Works in HSB color space. Default amount is set to 0.2 and changes B channel by this amount.
blue
(blue c)
Returns blue (third channel) value.
Examples
Usage
(blue 1385781)
;;=> 53.0
(blue :khaki)
;;=> 140.0
brighten
(brighten col)
(brighten col amt)
Change luma for givent color by given amount.
Works in LAB color space. Default amount is 1.0 and means change luma in LAB of 18.0.
See darken.
Examples
Make palette
(take 10 (iterate (fn [c] (brighten c 0.5)) "03100f"))
Given color
:khaki
[#f0e68c] :khaki
Brighten
(brighten :khaki 0.5)
[#ffffa4] #vec4 [255.0, 255.0, 164.31629723571075, 255.0]
ch0
(ch0 c)
Returns first channel value. Same as red.
Examples
Usage
(ch0 1385781)
;;=> 21.0
(ch0 :khaki)
;;=> 240.0
ch1
(ch1 c)
Returns second channel value. Same as green.
Examples
Usage
(ch0 1385781)
;;=> 21.0
(ch1 :khaki)
;;=> 230.0
ch2
(ch2 c)
Returns third channel value. Same as blue.
Examples
Usage
(ch0 1385781)
;;=> 21.0
(ch2 :khaki)
;;=> 140.0
clamp
(clamp c)
Clamp all color channels to [0-255]
range.
Examples
Usage
(clamp (color 304 -123 3.4 22.9))
;;=> [255.0 0.0 3.4 22.9]
color
(color c)
(color c a)
(color r g b)
(color r g b a)
Examples
Usage
(color :yellow)
;;=> [255.0 255.0 0.0 255.0]
(color :yellow 112)
;;=> [255.0 255.0 0.0 112.0]
(color 1 2 3)
;;=> [1.0 2.0 3.0 255.0]
(color 6 5 4 11)
;;=> [6.0 5.0 4.0 11.0]
Usage
(color 88 55 44 200)
[#58372cc8] #vec4 [88.0, 55.0, 44.0, 200.0]
color-converter
(color-converter cs ch1-scale ch2-scale ch3-scale ch4-scale)
(color-converter cs ch1-scale ch2-scale ch3-scale)
(color-converter cs ch-scale)
(color-converter cs)
Create function which converts provided color from cs
color space using ch-scale
as maximum value. (to simulate Processing colorMode
fn).
Arity:
- 1 - returns from-XXX* function
- 2 - sets the same maximum value for each channel
- 3 - sets individual maximum value without alpha, which is set to 0-255 range
- 4 - all channels have it’s own individual maximum value.
Examples
When you pass only color space, returns normalized from-XXX* function.
(color-converter :YUV)
;;=> clojure2d.color$from_YUV_STAR_@240a5e03
((color-converter :YUV) [158 94 85])
;;=> [98.41664563604795 199.87300611584595 98.66638916508842 255.0]
You can set maximum value for all channels or individually.
((color-converter :HCL 1.0) [0.5 0.5 0.5 0.5])
;;=> [135.01981120332636 7.989282785560203 7.7392236592269334 127.5]
((color-converter :HCL 100.0) [50 50 50 50])
;;=> [135.01981120332636 7.989282785560203 7.7392236592269334 127.5]
((color-converter :HCL 10 20 30) [5 10 15 127.5])
;;=> [135.01981120332636 7.989282785560203 7.7392236592269334 127.5]
((color-converter :HCL 10 20 30 40) [5 10 15 20])
;;=> [135.01981120332636 7.989282785560203 7.7392236592269334 127.5]
You can set maximum value for each channel separately. Here makes conversion from HSL color space where hue is from range 0-360, saturation and lightness from 0-100. Alpha is from range 0-255.
((color-converter :HCL 360.0 100.0 100.0) [240 50 50])
[#878708] #vec4 [134.93629417694882, 135.01981120332636, 7.7392236592269334, 255.0]
colorspaces
Map of all color spaces functions.
- key - name as keyword
- value - vector with functions containing to-XXX and from-XXX converters.
Examples
Example conversion
(let [[to from] (colorspaces :Cubehelix)] (mapv m/approx (from (to [100 200 50]))))
[#64c832] [100.0 200.0 50.0 255.0]
colorspaces*
Map of all color spaces functions (normalized).
- key - name as keyword
- value - vector with functions containing to-XXX* and from-XXX* converters.
Examples
Example conversion
(let [[to from] (colorspaces* :Cubehelix)] (mapv m/approx (from (to [100 200 50]))))
[#64c832] [100.0 200.0 50.0 255.0]
colorspaces-list
List of all color space names.
Examples
List of color spaces
colorspaces-list
;;=> (:CMY
;;=> :Cubehelix :DIN99
;;=> :DIN99b :DIN99c
;;=> :DIN99d :DIN99o
;;=> :GLHS :Gray
;;=> :HCL :HSB
;;=> :HSI :HSL
;;=> :HSV :HWB
;;=> :HunterLAB :IPT
;;=> :IgPgTg :JAB
;;=> :JCH :LAB
;;=> :LCH :LCHuv
;;=> :LMS :LUV
;;=> :OHTA :OSA
;;=> :Okhsl :Okhsv
;;=> :Okhwb :Oklab
;;=> :Oklch :PalettonHSV
;;=> :RGB :RYB
;;=> :UCS :UVW
;;=> :XYB :XYZ
;;=> :XYZ1 :YCbCr
;;=> :YCgCo :YDbDr
;;=> :YIQ :YPbPr
;;=> :YUV :Yxy
;;=> :linearRGB :sRGB)
complementary
(complementary c)
(complementary c colorspace)
Create complementary color. Possible colorspaces are:
:PalettonHSV
(default):HSB
,:HSV
,:HSL
or:HWB
:GLHS
contrast-ratio
(contrast-ratio c1 c2)
WCAG contrast ratio.
Based on YUV luma.
Examples
Contrast ratio
(contrast-ratio :pink :hotpink)
;;=> 1.721333484484812
Contrast ratio
(contrast-ratio :pink :purple)
;;=> 6.124032763373899
correct-luma
(correct-luma palette-or-gradient)
(correct-luma palette-or-gradient gradient-params)
Create palette or gradient with corrected luma to be linear.
See here
Examples
Before correction
(gradient [:black :red :yellow :white])
After correction
(correct-luma (gradient [:black :red :yellow :white]))
No correction
(palette [:lightyellow :orangered :deeppink :darkred] 9)
B-Spline interpolation
(palette [:lightyellow :orangered :deeppink :darkred]
9
{:colorspace :LAB, :interpolation :b-spline})
Lightness correction
(correct-luma (palette [:lightyellow :orangered :deeppink :darkred] 9))
Both
(correct-luma (palette [:lightyellow :orangered :deeppink :darkred]
9
{:colorspace :LAB, :interpolation :b-spline}))
darken
(darken col)
(darken col amt)
Change luma for givent color by given amount.
Works in LAB color space. Default amount is 1.0 and means change luma in LAB of -18.0.
See brighten.
Examples
Make palette
(take 10 (iterate (fn [c] (darken c 0.5)) :amber))
Given color
:khaki
[#f0e68c] :khaki
Darken
(darken :khaki 2.0)
[#8a8530] #vec4 [138.03857911998404, 132.60589663161204, 47.6473866116511, 255.0]
delta-C*
(delta-C* c1 c2)
ΔC*_ab difference, chroma difference in LAB color space, CIE 1976
delta-D-HCL
(delta-D-HCL c1 c2)
Color difference in HCL (Sarifuddin and Missaou) color space
delta-E*-2000
(delta-E*-2000 c1 c2)
(delta-E*-2000 c1 c2 l c h)
ΔE* color difference, CIE 2000
http://www2.ece.rochester.edu/~gsharma/ciede2000/ciede2000noteCRNA.pdf
delta-E*-CMC
(delta-E*-CMC c1 c2)
(delta-E*-CMC c1 c2 l c)
ΔE* CMC difference
Parameters l
and c
defaults to 1.0. Other common settings is l=2.0
and c=1.0
.
desaturate
(desaturate col)
(desaturate col amt)
Change color saturation in LCH color space.
Examples
Make palette
(take 10 (iterate desaturate (from-HSL (color 300 1.0 0.5))))
fe-color-matrix
(fe-color-matrix [r1 r2 r3 r4 r5 g1 g2 g3 g4 g5 b1 b2 b3 b4 b5 a1 a2 a3 a4 a5])
Create a feColorMatrix operator.
format-hex
(format-hex c)
Convert color to hex string (css).
When alpha is lower than 255.0, #rgba is returned.
Examples
Usage
(format-hex :maroon)
;;=> #800000
(format-hex (color 4 55 222))
;;=> #0437de
(format-hex (color 4 55 222 127.5))
;;=> #0437de80
from-CMY
CMY -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-CMY (to-CMY "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-CMY*
CMY -> RGB, alias for from-CMY
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-CMY* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Cubehelix
(from-Cubehelix c)
Cubehelix -> RGB
For ranges, see to-Cubehelix.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Cubehelix (to-Cubehelix "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Cubehelix*
(from-Cubehelix* c)
Cubehelix -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Cubehelix* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-DIN99
DIN99 -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-DIN99 (to-DIN99 "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-DIN99*
DIN99 -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-DIN99* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-DIN99b
DIN99b -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-DIN99b (to-DIN99b "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-DIN99b*
DIN99b -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-DIN99b* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-DIN99c
DIN99c -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-DIN99c (to-DIN99c "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-DIN99c*
DIN99c -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-DIN99c* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-DIN99d
DIN99d -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-DIN99d (to-DIN99d "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-DIN99d*
DIN99d -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-DIN99d* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-DIN99o
DIN99o -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-DIN99o (to-DIN99o "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-DIN99o*
DIN99o -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-DIN99o* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-GLHS
(from-GLHS c)
GLHS -> RGB
For ranges, see to-GLHS.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-GLHS (to-GLHS "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-GLHS*
(from-GLHS* c)
GLHS -> RGB
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-GLHS* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Gray
RGB -> Grayscale
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Gray (to-Gray "#7a03fe")))
[#2e2e2e] #vec4 [46.0, 46.0, 46.0, 255.0]
from-Gray*
RGB -> Grayscale
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Gray* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HCL
(from-HCL c)
HCL -> RGB, by Sarifuddin and Missaou.
For accepted ranges, see to-HCL.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HCL (to-HCL "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HCL*
(from-HCL* c)
HCL -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HCL* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HSB
HSB(V) -> RGB, normalized (see from-HSV)
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HSB (to-HSB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HSB*
HSB(V) -> RGB (see from-HSV*)
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HSB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HSI
(from-HSI c)
HSI -> RGB
For ranges, see to-HSI.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HSI (to-HSI "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HSI*
HSI -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HSI* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HSL
(from-HSL c)
HSL -> RGB
For ranges, see to-HSL.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HSL (to-HSL "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HSL*
HSL -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HSL* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HSV
(from-HSV c)
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HSV (to-HSV "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HSV*
HSV -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HSV* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HunterLAB
(from-HunterLAB c)
HunterLAB -> RGB
For ranges, see to-HunterLAB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HunterLAB (to-HunterLAB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HunterLAB*
(from-HunterLAB* c)
HunterLAB -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HunterLAB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-HWB
(from-HWB c)
HWB -> RGB
For ranges, see to-HWB.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-HWB (to-HWB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-HWB*
HWB -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-HWB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-IgPgTg
(from-IgPgTg c)
IgPgTg -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-IgPgTg (to-IgPgTg "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-IgPgTg*
(from-IgPgTg* c)
IgPgTg -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-IgPgTg* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-IPT
(from-IPT c)
IPT -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-IPT (to-IPT "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-IPT*
(from-IPT* c)
IPT -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-IPT* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-JAB
(from-JAB c)
JzAzBz -> RGB
For ranges, see to-JAB.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-JAB (to-JAB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-JAB*
(from-JAB* c)
JzAzBz -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-JAB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-JCH
(from-JCH c)
JCH -> RGB
For ranges, see to-JCH.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-JCH (to-JCH "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-JCH*
(from-JCH* c)
JCH -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-JCH* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-LAB
(from-LAB c)
LAB -> RGB,
For ranges, see to-LAB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-LAB (to-LAB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-LAB*
(from-LAB* c)
LAB -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-LAB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-LCH
(from-LCH c)
LCH -> RGB
For ranges, see to-LCH.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-LCH (to-LCH "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-LCH*
(from-LCH* c)
LCH -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-LCH* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-LCHuv
(from-LCHuv c)
LCHuv -> RGB
For ranges, see to-LCH.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-LCHuv (to-LCHuv "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-LCHuv*
(from-LCHuv* c)
LCHuv -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-LCHuv* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-linear
(from-linear v)
Gamma correction (gamma=1/2.4), lighten
Examples
Gamma correction
(from-linear 0.5)
;;=> 0.7353569830524495
from-linearRGB
linearRGB -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-linearRGB (to-linearRGB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-linearRGB*
linearRGB -> sRGB
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-linearRGB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-LMS
(from-LMS c)
LMS -> RGB, D65
Ranges: 0.0 - 100.0
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-LMS (to-LMS "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-LMS*
(from-LMS* c)
LMS -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-LMS* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-luma-color-hue
(from-luma-color-hue from c)
For given color space convert from polar representation of the color
from-LUV
(from-LUV c)
LUV -> RGB
For ranges, see to-LUV
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-LUV (to-LUV "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-LUV*
(from-LUV* c)
LUV -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-LUV* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-OHTA
(from-OHTA c)
OHTA -> RGB
For ranges, see to-OHTA.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-OHTA (to-OHTA "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-OHTA*
(from-OHTA* c)
OHTA -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-OHTA* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Okhsl
(from-Okhsl c)
Okhsl -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Okhsl (to-Okhsl "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Okhsl*
(from-Okhsl* c)
Okhsl -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Okhsl* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Okhsv
(from-Okhsv c)
Okhsv -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Okhsv (to-Okhsv "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Okhsv*
(from-Okhsv* c)
Okhsv -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Okhsv* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Okhwb
(from-Okhwb c)
Okhwb -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Okhwb (to-Okhwb "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Okhwb*
(from-Okhwb* c)
Okhwb -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Okhwb* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Oklab
(from-Oklab c)
Oklab -> RGB, see to-Oklab
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Oklab (to-Oklab "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Oklab*
(from-Oklab* c)
RGB -> Oklab, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Oklab* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Oklch
(from-Oklch c)
Oklch -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Oklch (to-Oklch "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Oklch*
(from-Oklch* c)
Oklch -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Oklch* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-OSA
(from-OSA c)
RGB -> OSA-UCS
For ranges, see to-OSA.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-OSA (to-OSA "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-OSA*
(from-OSA* c)
OSA-UCS -> RGB, normalized
Note that due to some extreme outliers, normalization is triple cubic power for g
and j
.
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-OSA* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-PalettonHSV
(from-PalettonHSV c)
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-PalettonHSV (to-PalettonHSV "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-PalettonHSV*
(from-PalettonHSV* c)
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-PalettonHSV* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-RGB
Alias for to-color
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-RGB (to-RGB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-RGB*
Alias for to-color
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-RGB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-RYB
(from-RYB c)
RYB -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-RYB (to-RYB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-RYB*
RYB -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-RYB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-sRGB
(from-sRGB c)
sRGB -> RGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-sRGB (to-sRGB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-sRGB*
sRGB -> linear RGB
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-sRGB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-UCS
(from-UCS c)
UCS -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-UCS (to-UCS "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-UCS*
(from-UCS* c)
UCS -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-UCS* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-UVW
(from-UVW c)
UVW -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-UVW (to-UVW "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-UVW*
(from-UVW* c)
UVW -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-UVW* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-XYB
(from-XYB c)
XYB -> sRGB
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-XYB (to-XYB "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-XYB*
(from-XYB* c)
XYB -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-XYB* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-XYZ
(from-XYZ c)
XYZ -> sRGB
For ranges, see to-XYZ
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-XYZ (to-XYZ "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-XYZ*
(from-XYZ* c)
XYZ -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-XYZ* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-XYZ1
(from-XYZ1 c)
XYZ -> sRGB, from range 0-1
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-XYZ1 (to-XYZ1 "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-XYZ1*
XYZ -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-XYZ1* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YCbCr
(from-YCbCr c)
YCbCr -> RGB
For ranges, see to-YCbCr.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YCbCr (to-YCbCr "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YCbCr*
(from-YCbCr* c)
YCbCr -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YCbCr* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YCgCo
(from-YCgCo c)
YCgCo -> RGB
For ranges, see to-YCgCo.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YCgCo (to-YCgCo "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YCgCo*
(from-YCgCo* c)
YCgCo -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YCgCo* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YDbDr
(from-YDbDr c)
YDbDr -> RGB
For ranges, see to-YDbDr.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YDbDr (to-YDbDr "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YDbDr*
(from-YDbDr* c)
YDbDr -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YDbDr* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YIQ
(from-YIQ c)
YIQ -> RGB
For ranges, see to-YIQ.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YIQ (to-YIQ "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YIQ*
(from-YIQ* c)
YIQ -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YIQ* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YPbPr
(from-YPbPr c)
YPbPr -> RGB
For ranges, see to-YPbPr.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YPbPr (to-YPbPr "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YPbPr*
(from-YPbPr* c)
YPbPr -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YPbPr* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-YUV
(from-YUV c)
YUV -> RGB
For ranges, see to-YUV.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-YUV (to-YUV "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-YUV*
(from-YUV* c)
YUV -> RGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-YUV* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
from-Yxy
(from-Yxy c)
Yxy -> sRGB
For ranges, see to-Yxy.
Examples
Converting to and from given color space should yield almost the same color.
(clojure2d.color/lclamp (from-Yxy (to-Yxy "#7a03fe")))
[#7a03fe] #vec4 [122.0, 3.0, 254.0, 255.0]
from-Yxy*
(from-Yxy* c)
Yxy -> sRGB, normalized
Examples
Gradient generated from given color space.
(clojure.core/fn [v]
(from-Yxy* (clojure2d.color/lerp [255 255 255] [0 0 0] v)))
get-channel
(get-channel col colorspace channel)
(get-channel col channel)
Get chosen channel. Works with any color space.
Examples
Usage
(get-channel :green 1)
;;=> 128.0
Get first channel from LAB representation of green.
(get-channel :green :LAB 0)
;;=> 46.227430171917774
gradient
(gradient)
(gradient palette-or-gradient-name)
(gradient palette-or-gradient-name options)
Return gradient function.
Grandient function accepts value from 0 to 1 and returns interpolated color.
Parameters;
palette-or-gradient-name
- name of the predefined gradient or palette (seq of colors).- (optional) additional parameters map:
:colorspace
- operate in given color space. Default::RGB
.:interpolation
- interpolation name or interpolation function. Interpolation can be one of interpolators-1d-list or easings-list. When easings is used, only first two colors are interpolated. Default::linear-smile
.:to?
- turn on/off conversion to given color space. Default:true
.:from?
- turn on/off conversion from given color space. Default:true
.:domain
- interpolation domain as seq of values for each color.
When called without parameters random gradient is returned.
Examples
Named gradient
(gradient :rainbow2)
Linear, RGB
(gradient (palette 5))
Linear, HSL
(gradient (palette 5) {:colorspace :HSL})
Linear, Yxy
(gradient (palette 5) {:colorspace :Yxy})
Cubic, Yxy
(gradient (palette 5) {:colorspace :Yxy, :interpolation :cubic-spline})
Loess, Yxy
(gradient (palette 5) {:colorspace :Yxy, :interpolation :loess})
RBF, Yxy
(gradient (palette 5)
{:colorspace :Yxy,
:interpolation (partial i/rbf (rbf/rbf :thin-plate))})
B-Spline for smoother colors in LAB
(gradient (palette 5) {:colorspace :LAB, :interpolation :b-spline})
Shepard, Yxy, irregular spacing
(gradient (palette 5)
{:colorspace :Yxy,
:interpolation :shepard,
:domain [0 0.1 0.15 0.8 1.0]})
Easing functions as interpolator
(gradient [[-120 0.1 0.2] [120 0.3 1.0]]
{:interpolation :bounce-in-out, :to? false, :colorspace :HSL})
Easy way to create palette from gradient
(palette (gradient [:blue :green]
{:colorspace :HSL, :interpolation :cubic-spline})
10)
Random predefined gradient
(gradient)
Cool
(gradient :cool)
Warm
(gradient :warm)
Cubehelix
(gradient :cubehelix)
IQ 1
(gradient :iq-1)
gradient-cubehelix
Cubehelix gradient generator from two colors.
Examples
Cubehelix gradient
(gradient-cubehelix [[300 0.2 0.2] [200 0.8 0.9]])
gray
(gray v)
(gray v a)
Create grayscale color based on intensity v
. Optional parameter alpha a
.
See also color
Examples
Usage
(gray 123)
[#7b7b7b] #vec4 [123.0, 123.0, 123.0, 255.0]
green
(green c)
Returns green (second channel) value.
Examples
Usage
(green 1385781)
;;=> 37.0
(green :khaki)
;;=> 230.0
hue
(hue c)
Hue value of color (any representation). Returns angle (0-360).
Uses hexagonal transformation. See also hue-polar.
Examples
Usage
(hue :red)
;;=> 0.0
(hue :green)
;;=> 120.0
(hue :blue)
;;=> 240.0
(hue "#12f5e6")
;;=> 176.0352422907489
(hue-polar "#12f5e6")
;;=> 176.61308941261146
(hue-paletton "#4455f6")
;;=> 251.00297936547298
hue-paletton
(hue-paletton r g b)
(hue-paletton c)
Convert color to paletton HUE (which is different than hexagon or polar conversion).
Examples
Convert RGB to paletton hue.
(hue :amber)
;;=> 47.19101123595505
(hue-polar :amber)
;;=> 48.30634125595805
(hue-paletton :amber)
;;=> 82.00581517567336
(hue-paletton 22 33 123)
;;=> 250.38350628797656
hue-polar
(hue-polar c)
Hue value of color (any representation). Returns angle (0-360).
Uses polar transformation. See also hue.
Examples
Usage
(hue-polar "#4455f6")
;;=> 235.0358615462941
(hue "#4455f6")
;;=> 234.26966292134833
(hue-paletton "#4455f6")
;;=> 251.00297936547298
iq-gradient
(iq-gradient c1 c2)
(iq-gradient a b c d)
Create gradient generator function with given parametrization or two colors.
See http://iquilezles.org/www/articles/palettes/palettes.htm and https://github.com/thi-ng/color/blob/master/src/gradients.org#gradient-coefficient-calculation
Parameters should be Vec3
type.
Examples
Create gradient from 4 coeffs
(iq-gradient [0.5 0.5 0.5] [0.4 0.5 0.6] [0.2 0.2 1.0] [1.0 0.1 1.0])
Create gradient from two colors
(iq-gradient :red :blue)
lclamp
(lclamp c)
Clamp all color channels to [0-255]
range. Round if necessary.
Examples
Usage
(lclamp (color 304 -123 3.4 22.9))
;;=> [255.0 0.0 3.0 23.0]
lerp
(lerp c1 c2 colorspace t)
(lerp c1 c2)
(lerp c1 c2 t)
Examples
Usage
[(lerp :red :blue 0) (lerp :red :blue 0.5) (lerp :red :blue 1.0)]
As gradient
(partial lerp :red :blue)
lerp+
(lerp+ c1 c2 colorspace amount)
(lerp+ c1 c2)
(lerp+ c1 c2 amount)
Linear interpolation of two colors conserving luma of the second color.
Amount: strength of the blend (defaults to 0.5).
See also lerp-.
Examples
Usage
[(lerp+ :red :blue 0) (lerp+ :red :blue 0.5) (lerp+ :red :blue 1.0)]
As gradient
(partial lerp+ :red :blue)
lerp-
(lerp- c1 c2 colorspace amount)
(lerp- c1 c2)
(lerp- c1 c2 amount)
Linear interpolation of two colors conserving luma of the first color.
Amount: strength of the blend (defaults to 0.5)
See also lerp+.
Examples
Usage
[(lerp- :red :blue 0) (lerp- :red :blue 0.5) (lerp- :red :blue 1.0)]
As gradient
(partial lerp- :red :blue)
luma
(luma c)
Returns luma
Examples
Usage
(luma 1385781)
;;=> 34.751968
(luma :red)
;;=> 54.231105
make-LCH
(make-LCH cs)
Create LCH conversion functions pair from any luma based color space.
merge-gradients
(merge-gradients g1 g2 midpoint)
(merge-gradients g1 g2)
Combine two gradients, optionally select midpoint
(0.5 by default).
Resulting gradient has colors from g1
for values lower than midpoint
and from g2
for values higher than midpoint
mix
(mix c1 c2 colorspace t)
(mix c1 c2)
(mix c1 c2 t)
Mix colors in given optional colorspace
(default: :RGB
) and optional ratio (default: 0.5).
chroma.js way
Examples
Mix
(mix :red :blue)
[#b400b4] #vec4 [180.31222920256963, 0.0, 180.31222920256963, 255.0]
As gradient
(partial mix :red :blue)
Mix, different ratio
(mix :red :blue 0.25)
[#dd0080] #vec4 [220.83647796503186, 0.0, 127.5, 255.0]
Mix in LAB
(mix :red :blue :LAB 0.5)
[#d90052] #vec4 [217.32276724142096, -71.75486055938082, 82.18494583171135, 255.0]
Mix in HSI
(mix :red :blue :HSI 0.5)
[#008b74] #vec4 [0.0, 139.46413097289692, 115.5358690271031, 255.0]
mixbox
(mixbox col1 col2)
(mixbox col1 col2 t)
Pigment based color mixing.
mixsub
(mixsub c1 c2 colorspace t)
(mixsub c1 c2)
(mixsub c1 c2 t)
Subtractive color mix in given optional colorspace
(default: :RGB
) and optional ratio (default: 0.5)
modulate
(modulate col colorspace channel amount)
(modulate col channel amount)
Modulate (multiply) chosen channel by given amount. Works with any color space.
Examples
More red
(modulate [123 22 233] 0 1.2)
[#9416e9] #vec4 [147.6, 22.0, 233.0, 255.0]
More saturation
(modulate [123 22 233] :HSL 1 1.2)
[#7a01fe] #vec4 [122.09999999999981, 0.9000000000000166, 254.09999999999997, 255.0]
Decrease luma
(mapv (fn* [p1__23250#] (modulate p1__23250# :LAB 0 0.8)) (palette 0))
named-colors-list
(named-colors-list)
Return list of the named colors.
Examples
List of color names
(named-colors-list)
;;=> (:aquamarine
;;=> :medium-violetred
;;=> :docc/green :lime
;;=> :deep-skyblue :deepskyblue
;;=> :medium-slateblue :docc/burnt-sienna
;;=> :docc/apricot-yellow :darksalmon
;;=> :antiquewhite :docc/vinaceous-cinnamon
;;=> :mediumturquoise :docc/ochraceous-salmon
;;=> :slategrey :docc/salvia-blue
;;=> :docc/golden-yellow :docc/jasper-red
;;=> :sandy-brown :docc/pistachio-green
;;=> :slategray :docc/olive-yellow
;;=> :sienna :docc/cinnamon-rufous
;;=> :orange :navajowhite
;;=> :docc/dull-violet-black :docc/light-grayish-olive
;;=> :medium-turquoise :docc/naples-yellow
;;=> :lavenderblush :docc/venice-green
;;=> :rosy-brown :yellow-green
;;=> :firebrick :docc/vinaceous-tawny
;;=> :alice-blue :orangered
;;=> :docc/olympic-blue :docc/warm-gray
;;=> :orange-red :palevioletred
;;=> :lawngreen :docc/mineral-gray
;;=> :docc/cotinga-purple :docc/yellow-orange
;;=> :docc/red-violet :docc/helvetia-blue
;;=> :docc/lilac :docc/cream-yellow
;;=> :medium-aquamarine :seashell
;;=> :lightpink :darkolivegreen
;;=> :aliceblue :deep-pink
;;=> :docc/vandar-poel-s-blue :blue-violet
;;=> :docc/purple-drab :dark-orange
;;=> :gray :lightsteelblue
;;=> :whitesmoke :sea-green
;;=> :light-pink :docc/deep-violet---plumbeous
;;=> :green-yellow :darkgoldenrod
;;=> :dark-seagreen :docc/pale-king-s-blue
;;=> :tan :docc/light-porcelain-green
;;=> :docc/cobalt-green :docc/maple
;;=> :light-salmon :docc/sulpher-yellow
;;=> :bisque :white
;;=> :midnight-blue :peach-puff
;;=> :lavender-blush :slate-gray
;;=> :docc/hay-s-russet :docc/light-green-yellow
;;=> :lightgreen :docc/red-orange
;;=> :dark-orchid :darkseagreen
;;=> :crimson :darkslategray
;;=> :docc/brick-red :pale-violetred
;;=> :docc/rainette-green :mistyrose
;;=> :antique-white :chocolate
;;=> :yellow :docc/dusky-green
;;=> :floral-white :docc/violet-blue
;;=> :docc/dull-viridian-green :medium-purple
;;=> :docc/light-glaucous-blue :indian-red
;;=> :docc/light-brown-drab :cadetblue
;;=> :docc/spectrum-red :navy
;;=> :old-lace :ghostwhite
;;=> :docc/eugenia-red---a :dimgrey
;;=> :docc/olive :docc/rosolanc-purple
;;=> :docc/vandyke-brown :rebeccapurple
;;=> :seagreen :docc/peacock-blue
;;=> :docc/dusky-madder-violet :green
;;=> :dark-goldenrod :mediumseagreen
;;=> :indigo :dark-slateblue
;;=> :docc/neutral-gray :olivedrab
;;=> :docc/benzol-green :cyan
;;=> :peachpuff :limegreen
;;=> :docc/eosine-pink :docc/grenadine-pink
;;=> :docc/citron-yellow :docc/light-mauve
;;=> :saddle-brown :burly-wood
;;=> :mediumslateblue :violet
;;=> :docc/lemon-yellow :light-coral
;;=> :sandybrown :spring-green
;;=> :docc/taupe-brown :docc/turquoise-green
;;=> :docc/deep-indigo :docc/ivory-buff
;;=> :docc/black :white-smoke
;;=> :yellowgreen :docc/sudan-brown
;;=> :mediumspringgreen :docc/olive-buff
;;=> :dark-red :docc/old-rose
;;=> :docc/yellow-green :docc/krongbergs-green
;;=> :steelblue :docc/deep-slate-green
;;=> :rosybrown :cornflowerblue
;;=> :ivory :lightgoldenrodyellow
;;=> :docc/cameo-pink :docc/indian-lake
;;=> :docc/english-red :salmon
;;=> :docc/grayish-lavender---b :docc/citrine
;;=> :darkcyan :dark-violet
;;=> :docc/lincoln-green :peru
;;=> :cornsilk :lightslategray
;;=> :docc/glaucous-green :blueviolet
;;=> :forestgreen :docc/dull-blue-violet
;;=> :docc/olive-green :dark-gray
;;=> :navajo-white :docc/pale-raw-umber
;;=> :lightseagreen :docc/corinthian-pink
;;=> :misty-rose :docc/cinnamon-buff
;;=> :docc/ecru :gold
;;=> :docc/dark-tyrian-blue :gainsboro
;;=> :darkorchid :docc/grayish-lavender---a
;;=> :burlywood :lightskyblue
;;=> :chartreuse :lemon-chiffon
;;=> :docc/laelia-pink :snow
;;=> :docc/dark-slate-purple :medium-seagreen
;;=> :moccasin :docc/white
;;=> :docc/deep-slate-olive :honeydew
;;=> :aqua :darkred
;;=> :docc/oil-green :docc/fresh-color
;;=> :docc/green-blue :mediumorchid
;;=> :lightsalmon :dodger-blue
;;=> :dim-gray :saddlebrown
;;=> :wheat :springgreen
;;=> :hot-pink :docc/sepia
;;=> :lightslategrey :docc/apricot-orange
;;=> :darkblue :powderblue
;;=> :docc/yellow-ocher :light-grey
;;=> :turquoise :blanchedalmond
;;=> :docc/carmine-red :papayawhip
;;=> :slateblue :lightblue
;;=> :light-seagreen :royal-blue
;;=> :docc/nile-blue :docc/madder-brown
;;=> :docc/dark-soft-violet :skyblue
;;=> :light-skyblue :light-slategray
;;=> :red :lightyellow
;;=> :docc/eugenia-red---b :blue
;;=> :mint-cream :medium-blue
;;=> :palegreen :docc/diamine-green
;;=> :greenyellow :docc/calamine-blue
;;=> :docc/night-green :khaki
;;=> :maroon :docc/scarlet
;;=> :cornflower-blue :dark-magenta
;;=> :darkgrey :midnightblue
;;=> :floralwhite :deeppink
;;=> :docc/violet-red :paleturquoise
;;=> :docc/light-brownish-olive :dark-green
;;=> :docc/pansy-purple :darkkhaki
;;=> :azure :medium-orchid
;;=> :indianred :darkviolet
;;=> :mediumpurple :fuchsia
;;=> :docc/isabella-color :fire-brick
;;=> :coral :docc/peach-red
;;=> :docc/slate-color :dark-blue
;;=> :mediumvioletred :lemonchiffon
;;=> :mediumblue :docc/seashell-pink
;;=> :docc/brown :docc/olive-ocher
;;=> :darkmagenta :goldenrod
;;=> :darkorange :orchid
;;=> :plum :pink
;;=> :teal :docc/dark-citrine
;;=> :lawn-green :magenta
;;=> :amber :forest-green
;;=> :docc/sea-green :light-green
;;=> :docc/pyrite-yellow :dark-cyan
;;=> :lightgrey :dark-turquoise
;;=> :dark-slategray :light-blue
;;=> :light-steelblue :docc/veronia-purple
;;=> :pale-goldenrod :slate-blue
;;=> :docc/artemesia-green :powder-blue
;;=> :docc/vistoris-lake :docc/chromium-green
;;=> :purple :olive-drab
;;=> :docc/light-pinkish-cinnamon :ghost-white
;;=> :dodgerblue :docc/blackish-olive
;;=> :steel-blue :docc/andover-green
;;=> :darkturquoise :cadet-blue
;;=> :mintcream :docc/orange-rufous
;;=> :pale-green :docc/hermosa-pink
;;=> :docc/violet-carmine :hotpink
;;=> :docc/orange-citrine :docc/orange
;;=> :docc/vandyke-red :thistle
;;=> :docc/pale-burnt-lake :docc/khaki
;;=> :docc/dark-greenish-glaucous :light-goldenrodyellow
;;=> :docc/mars-brown-tobacco :docc/sulphine-yellow
;;=> :docc/cerulian-blue :royalblue
;;=> :blanched-almond :docc/pinkish-cinnamon
;;=> :darkgreen :light-cyan
;;=> :darkslateblue :docc/deep-lyons-blue
;;=> :silver :docc/pomegranite-purple
;;=> :darkgray :docc/spinel-red
;;=> :grey :docc/hydrangea-red
;;=> :oldlace :docc/cossack-green
;;=> :dark-salmon :mediumaquamarine
;;=> :brown :lightgray
;;=> :docc/dark-medici-blue :docc/ochre-red
;;=> :docc/deep-grayish-olive :docc/pompeian-red
;;=> :docc/pale-lemon-yellow :olive
;;=> :docc/yellow :lightcoral
;;=> :docc/orange-yellow :tomato
;;=> :docc/buffy-citrine :docc/carmine
;;=> :docc/aconite-violet :docc/antwarp-blue
;;=> :lightcyan :linen
;;=> :docc/violet :darkslategrey
;;=> :lavender :docc/blue-violet
;;=> :papaya-whip :docc/raw-sienna
;;=> :docc/blue :docc/fawn
;;=> :dark-olivegreen :docc/coral-red
;;=> :docc/eupatorium-purple :docc/red
;;=> :docc/etruscan-red :dimgray
;;=> :dark-khaki :palegoldenrod
;;=> :medium-springgreen :beige
;;=> :black :light-yellow)
nearest-color
(nearest-color pal c dist-fn)
(nearest-color pal c)
(nearest-color pal)
Find nearest color from a set. Input: distance function (default euclidean), list of target colors and source color.
Examples
Find nearest color to given color from below palette.
[120 0 80]
[#780050] [120 0 80]
All below examples are using this palette
some-palette
With Delta C
(nearest-color some-palette [120 0 80] delta-c)
[#5c68c3] #vec4 [91.88783821894172, 104.00236957918251, 195.37991511635713, 255.0]
With Delta H
(nearest-color some-palette [120 0 80] delta-h)
[#0a166b] #vec4 [10.469422197801668, 21.711850993058505, 106.51129709945782, 255.0]
With Delta E CIE
(nearest-color some-palette [120 0 80] delta-e-cie)
[#0a166b] #vec4 [10.469422197801668, 21.711850993058505, 106.51129709945782, 255.0]
With Delta E CMC
(nearest-color some-palette [120 0 80] delta-e-cmc)
[#111f88] #vec4 [16.788395487095283, 30.69119283998515, 135.5572797261189, 255.0]
With euclidean
(nearest-color some-palette [120 0 80])
[#0a166b] #vec4 [10.469422197801668, 21.711850993058505, 106.51129709945782, 255.0]
noticable-different?
(noticable-different? c1 c2)
(noticable-different? c1 c2 s p)
Returns noticable difference (true/false) between colors.
Defined in: https://research.tableau.com/sites/default/files/2014CIC_48_Stone_v3.pdf
Implementation from: https://github.com/connorgr/d3-jnd/blob/master/src/jnd.js
Examples
Contrast ratio
(noticable-different? :pink :hotpink)
;;=> true
Contrast ratio
(noticable-different? "00aabb" "00baba")
;;=> false
pack
(pack c)
Pack color to ARGB 32bit integer.
Examples
Pack colors into 32 bit int.
(pack :green)
;;=> -16744448
(pack (color 12 33 255))
;;=> -15982081
See the difference about treating alpha when packing raw integer.
(pack 1123071)
;;=> 1123071
(pack (to-color 1123071))
;;=> -15654145
palette
(palette)
(palette p)
(palette p number-of-colors)
(palette p number-of-colors gradient-params)
Get palette.
If argument is a keyword, returns one from palette presets. If argument is a number, returns one from colourlovers palettes. If argument is a gradient, returns 5 or number-of-colors
samples.
If called without argument, random palette is returned
Optionally you can pass number of requested colors and other parameters as in resample
Examples
Named palette
(palette :set3)
Colourlovers palette
(palette 0)
Resampled palette
(palette 0 10)
Resampled palette with interpolation and color space
(palette 0 10 {:colorspace :LUV, :interpolation :loess})
Sampled from gradient
(palette (gradient :cyan-magenta))
Sampled from gradient with number of colors
(palette (gradient :cyan-magenta) 10)
Random predefined palette
(palette)
paletton
multimethod
Create paletton palette.
Input:
- type - one of:
:monochromatic
(one hue),:triad
(three hues),:tetrad
(four hues) - hue - paletton version of hue (use hue-paletton to get hue value).
- configuration as a map
Configuration consist:
:preset
- one of paletton-presets-list, default:full
.:compl
- generate complementary color?, defaultfalse
. Works with:monochromatic
and:triad
:angle
- hue angle for additional colors for:triad
and:tetrad
.:adj
- for:triad
only, generate adjacent (defaulttrue
) values or not.
Examples
Monochromatic dark-neon palette
(paletton :monochromatic 140 {:preset :dark-neon})
Monochromatic full (default) palette
(paletton :monochromatic 140)
Monochromatic shiny palette with complementary color
(paletton :monochromatic 300 {:preset :shiny, :compl true})
Triad full palette, angle 30
(paletton :triad 120)
Triad palette, angle 10 with complementary
(paletton :triad 120 {:preset :pastels-dark, :angle 10, :compl true})
Triad palette, angle 10 with complementary, not adjacent version
(paletton :triad
120
{:adj false, :preset :pastels-dark, :angle 10, :compl true})
Tetrad palette
(paletton :tetrad 20 {:preset :pastels-darkest})
Tetrad palette, bigger angle
(paletton :tetrad 20 {:angle 100, :preset :pastels-darkest})
paletton-presets-list
Paletton presets names
Examples
List of all paletton presets
paletton-presets-list
;;=> (:pastels :pastels-bright
;;=> :pastels-med :pastels-lightest
;;=> :full :pastels-dark
;;=> :shiny :darkest
;;=> :pastels-light :pastels-very-dark
;;=> :almost-gray-darker :pale-light
;;=> :pastels-darkest :dark
;;=> :pastels-very-light :pastels-mid-pale
;;=> :almost-gray-mid :almost-gray-dark
;;=> :pastels-mid-dark :dark-neon
;;=> :almost-black :darker
;;=> :almost-gray-lighter :almost-gray-light)
possible-color?
(possible-color? c)
Check if given argument can be considered as color.
Check is done by analyzing type of the argument.
See also valid-color?.
Examples
Usage
(possible-color? :blue)
;;=> true
(possible-color? :not-a-color)
;;=> true
(possible-color? [1 2 3 255])
;;=> true
(possible-color? [:red :green :blue])
;;=> false
(possible-color? (gradient [:red :blue]))
;;=> false
possible-palette?
(possible-palette? c)
Check if given argument can be considered as palette.
Check is done by analyzing type of the argument.
Examples
Usage
(possible-palette? :blue)
;;=> false
(possible-palette? [1 2 3 255])
;;=> false
(possible-palette? [:red :green :blue])
;;=> true
(possible-palette? (gradient [:red :blue]))
;;=> false
random-color
(random-color color-theme alpha)
(random-color alpha-or-color-theme)
(random-color)
Generate random color.
Optionally color theme or alpha can be provided.
List of possible color themes is stored in color-themes
var. These are taken from thi.ng and paletton.
Examples
Random color
(random-color)
[#bf5892] :docc/eupatorium-purple
Random color (with alpha set)
(random-color 180)
[#6a5acdb4] #vec4 [106.0, 90.0, 205.0, 180.0]
random-gradient
(random-gradient)
Generate random gradient function.
Examples
Randomly generated gradient
(random-gradient)
Randomly generated gradient
(random-gradient)
Randomly generated gradient
(random-gradient)
random-palette
(random-palette)
Generate random palette from all collections defined in clojure2d.color namespace.
Examples
Randomly generated palette
(random-palette)
Randomly generated palette
(random-palette)
Randomly generated palette
(random-palette)
red
(red c)
Returns red (first channel) value.
Examples
Usage
(red 1385781)
;;=> 21.0
(red :khaki)
;;=> 240.0
reduce-colors
(reduce-colors xs number-of-colors)
(reduce-colors xs number-of-colors colorspace-or-dist)
Reduce colors using x-means clustering in given colorspace
(default :RGB
).
Use for long sequences (for example to generate palette from image).
Examples
Reduce cockatoo image palette (2 colors)
(reduce-colors i1 2)
Reduce cockatoo image palette in LAB (2 colors)
(reduce-colors i1 2 :LAB)
Reduce cockatoo image palette (6 colors)
(reduce-colors i1 6)
Reduce cockatoo image palette in LAB (6 colors)
(reduce-colors i1 6 :LAB)
Reduce cockatoo image palette (15 colors)
(reduce-colors i1 15)
Reduce cockatoo image palette in LAB (15 colors)
(reduce-colors i1 15 :LAB)
relative-luma
(relative-luma c)
Returns relative luminance
Examples
Usage
(relative-luma 1385781)
;;=> 4.43566261779254
(relative-luma :red)
;;=> 54.231105
resample
(resample pal number-of-colors)
(resample pal number-of-colors gradient-params)
Resample palette.
Internally it’s done by creating gradient and sampling back to colors. You can pass gradient parameters like colorspace, interpolator name and domain.
Examples
Input palette
(palette 12)
Resample one of the colourlovers palette.
(resample (palette 12) 16)
Resample one of the colourlovers palette. Different gradient settings.
(resample (palette 12)
16
{:colorspace :LUV, :interpolation :cubic-spline})
saturate
(saturate col)
(saturate col amt)
Change color saturation in LCH color space.
Examples
Make palette
(take 10 (iterate saturate (from-HSL (color 300 0.0 0.5))))
scale
(scale c v)
(scale c v alpha?)
Multiply color channels by given value, do not change alpha channel by default
set-alpha
(set-alpha c a)
Set alpha channel and return new color
Examples
Usage
(set-alpha :khaki 200)
[#f0e68cc8] #vec4 [240.0, 230.0, 140.0, 200.0]
set-awt-alpha
(set-awt-alpha c a)
Set alpha channel and return Color
representation.
Examples
Usage
(set-awt-alpha :khaki 200)
[#f0e68cc8] java.awt.Color[r=240,g=230,b=140]
set-blue
(set-blue c val)
Set blue channel and return new color
Examples
Usage
(set-blue :khaki 11)
[#f0e60b] #vec4 [240.0, 230.0, 11.0, 255.0]
set-ch0
(set-ch0 c val)
Set red channel and return new color.
Examples
Usage
(set-ch0 :khaki 11)
[#0be68c] #vec4 [11.0, 230.0, 140.0, 255.0]
set-ch1
(set-ch1 c val)
Set green channel and return new color.
Examples
Usage
(set-ch1 :khaki 11)
[#f00b8c] #vec4 [240.0, 11.0, 140.0, 255.0]
set-ch2
(set-ch2 c val)
Set blue channel and return new color
Examples
Usage
(set-ch2 :khaki 11)
[#f0e60b] #vec4 [240.0, 230.0, 11.0, 255.0]
set-channel
(set-channel col colorspace channel val)
(set-channel col channel val)
Set chosen channel with given value. Works with any color space.
set-green
(set-green c val)
Set green channel and return new color.
Examples
Usage
(set-green :khaki 11)
[#f00b8c] #vec4 [240.0, 11.0, 140.0, 255.0]
set-red
(set-red c val)
Set red channel and return new color.
Examples
Usage
(set-red :khaki 11)
[#0be68c] #vec4 [11.0, 230.0, 140.0, 255.0]
temperature
(temperature t)
Color representing given black body temperature t
in Kelvins (or name as keyword).
Reference: CIE 1964 10 degree CMFs
Using improved interpolation functions.
Possible temperature names: :candle
, :sunrise
, :sunset
, :lightbulb
, :morning
, :moonlight
, :midday
, :cloudy-sky
, :blue-sky
, :warm
, :cool
, :white
, :sunlight
Examples
Warm
(temperature :warm)
[#ffb165] #vec4 [255.0, 176.72614289160697, 100.85156825287878, 255.0]
Blue sky
(temperature :blue-sky)
[#ccdbff] #vec4 [203.92568056580265, 219.30626754966096, 255.0, 255.0]
3000K
(temperature 3000)
[#ffb46b] #vec4 [255.0, 180.23679378180316, 107.44230365747522, 255.0]
tinter
(tinter tint-color)
Creates fn to tint color using other color(s).
tint-color
Examples
Input palette
(palette [:red :yellow] 10)
Make any color red
(map (tinter [255 55 55]) (palette [:red :yellow] 10))
to-awt-color
(to-awt-color c)
Convert any color representation to java.awt.Color
.
Examples
Various conversions
(to-awt-color :khaki)
;;=> java.awt.Color[r=240,g=230,b=140]
(to-awt-color 2853249587)
;;=> java.awt.Color[r=17,g=34,b=51]
to-CMY
(to-CMY c)
RGB -> CMY
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :CMY})
Convert into color space value
(to-CMY :peru)
;;=> [50.0 122.0 192.0 255.0]
to-CMY*
CMY -> RGB, alias for to-CMY
Examples
Convert into color space value
(to-CMY* :peru)
;;=> [50.0 122.0 192.0 255.0]
to-color
(to-color c)
Convert any color representation to Vec4
vector.
Examples
Various conversions
(to-color :khaki)
;;=> [240.0 230.0 140.0 255.0]
(to-color "abcc12")
;;=> [171.0 204.0 18.0 255.0]
(to-color "#1234af")
;;=> [18.0 52.0 175.0 255.0]
(to-color "#1234af80")
;;=> [18.0 52.0 175.0 128.0]
(to-color "a")
;;=> [170.0 170.0 170.0 255.0]
(to-color "4a")
;;=> [74.0 74.0 74.0 255.0]
(to-color "fac")
;;=> [255.0 170.0 204.0 255.0]
(to-color (v/vec2 120 120))
;;=> [120.0 120.0 120.0 120.0]
(to-color (v/vec3 144 133.3 122))
;;=> [144.0 133.3 122.0 255.0]
(to-color (v/vec4 111 122 133 44))
;;=> [111.0 122.0 133.0 44.0]
(to-color [30 40 50])
;;=> [30.0 40.0 50.0 255.0]
(to-color (range 200 220 5))
;;=> [200.0 205.0 210.0 215.0]
(to-color 2868903659)
;;=> [255.0 254.0 235.0 170.0]
to-Cubehelix
(to-Cubehelix c)
RGB -> Cubehelix
D3 version
Ranges:
- H: 0.0 - 360.0
- S: 0.0 - 4.61
- L: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Cubehelix})
Convert into color space value
(to-Cubehelix :peru)
;;=> [25.666885833319213 0.8269520406177997 0.5760783984025756 255.0]
to-Cubehelix*
(to-Cubehelix* c)
RGB -> Cubehelix, normalized
Examples
Convert into color space value
(to-Cubehelix* :peru)
;;=> [18.18105013622813 45.69897938512506 146.89999159265676 255.0]
to-DIN99
RGB -> DIN99
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :DIN99})
Convert into color space value
(to-DIN99 :peru)
;;=> [71.84453824167862 18.635053777666155 15.512419941341172 255.0]
to-DIN99*
RGB -> DIN99, normalized
Examples
Convert into color space value
(to-DIN99* :peru)
;;=> [183.20300148703927 184.70175859642342 193.20544693282423 255.0]
to-DIN99b
RGB -> DIN99
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :DIN99b})
Convert into color space value
(to-DIN99b :peru)
;;=> [65.52906131541887 17.306064069097136 30.962381838009414 255.0]
to-DIN99b*
RGB -> DIN99b, normalized
Examples
Convert into color space value
(to-DIN99b* :peru)
;;=> [167.09965962999127 170.97253910584988 214.72047048070252 255.0]
to-DIN99c
RGB -> DIN99
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :DIN99c})
Convert into color space value
(to-DIN99c :peru)
;;=> [65.36819954639269 14.373825440228915 30.260644749408627 255.0]
to-DIN99c*
RGB -> DIN99c, normalized
Examples
Convert into color space value
(to-DIN99c* :peru)
;;=> [166.68952307721386 164.0144544839051 214.70835553612187 255.0]
to-DIN99d
RGB -> DIN99
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :DIN99d})
Convert into color space value
(to-DIN99d :peru)
;;=> [65.28705111878932 12.045888870714975 29.866044941857794 255.0]
to-DIN99d*
RGB -> DIN99d, normalized
Examples
Convert into color space value
(to-DIN99d* :peru)
;;=> [166.48169058814776 158.0962213067943 215.05000111884405 255.0]
to-DIN99o
RGB -> DIN99
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :DIN99o})
Convert into color space value
(to-DIN99o :peru)
;;=> [65.52906131541887 29.11304566099543 20.232209198269828 255.0]
to-DIN99o*
RGB -> DIN99o, normalized
Examples
Convert into color space value
(to-DIN99o* :peru)
;;=> [167.09965962999127 195.21849337998404 186.91100026409774 255.0]
to-GLHS
(to-GLHS c)
RGB -> GLHS
Color Theory and Modeling for Computer Graphics, Visualization, and Multimedia Applications (The Springer International Series in Engineering and Computer Science) by Haim Levkowitz
Weights: 0.2 (min), 0.1 (mid), 0.7 (max).
Ranges:
- L: 0.0 - 1.0
- H: 0.0 - 360.0
- S: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :GLHS})
Convert into color space value
(to-GLHS :peru)
;;=> [0.6643137254901961 29.577464788732396 0.628099173553719 255.0]
to-GLHS*
(to-GLHS* c)
RGB -> GLHS, normalized
Examples
Convert into color space value
(to-GLHS* :peru)
;;=> [169.4 20.96440645179119 160.16528925619835 255.0]
to-Gray
(to-Gray c)
RGB -> Grayscale
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Gray})
Convert into color space value
(to-Gray :peru)
;;=> [143.26048200000002 143.26048200000002 143.26048200000002 255.0]
to-Gray*
RGB -> Grayscale
Examples
Convert into color space value
(to-Gray* :peru)
;;=> [143.26048200000002 143.26048200000002 143.26048200000002 255.0]
to-HCL
(to-HCL c)
RGB -> HCL, by Sarifuddin and Missaou.
lambda = 3.0
Returned ranges:
- H: -180.0 - 180.0
- C: 0.0 - 170.0
- L: 0.0 - 135.266
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HCL})
Convert into color space value
(to-HCL :peru)
;;=> [29.462047029931753 95.5434828525016 103.74112713628747 255.0]
to-HCL*
(to-HCL* c)
RGB -> HCL, normalized
Examples
Convert into color space value
(to-HCL* :peru)
;;=> [148.32438865897458 143.3152242787524 195.5702524834639 255.0]
to-HSB
RGB -> HSB(V), normalized (see to-HSV)
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HSB})
Convert into color space value
(to-HSB :peru)
;;=> [29.577464788732396 0.6926829268292682 0.803921568627451 255.0]
to-HSB*
RGB -> HSB(V) (see to-HSV*)
Examples
Convert into color space value
(to-HSB* :peru)
;;=> [20.950704225352116 176.6341463414634 205.0 255.0]
to-HSI
(to-HSI c)
RGB -> HSI
Ranges:
- H: 0.0 - 360
- S: 0.0 - 1.0
- I: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HSI})
Convert into color space value
(to-HSI :peru)
;;=> [29.577464788732396 0.5286783042394014 0.5241830065359476 255.0]
to-HSI*
RGB -> HSI, normalized
Examples
Convert into color space value
(to-HSI* :peru)
;;=> [20.950704225352116 134.81296758104736 133.66666666666666 255.0]
to-HSL
(to-HSL c)
RGB -> HSL
Ranges:
- H: 0.0 - 360
- S: 0.0 - 1.0
- L: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HSL})
Convert into color space value
(to-HSL :peru)
;;=> [29.577464788732396 0.5867768595041323 0.5254901960784314 255.0]
to-HSL*
RGB -> HSL, normalized
Examples
Convert into color space value
(to-HSL* :peru)
;;=> [20.950704225352116 149.62809917355372 134.0 255.0]
to-HSV
(to-HSV c)
RGB -> HSV
Ranges:
- H: 0.0 - 360
- S: 0.0 - 1.0
- V: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HSV})
Convert into color space value
(to-HSV :peru)
;;=> [29.577464788732396 0.6926829268292682 0.803921568627451 255.0]
to-HSV*
RGB -> HSV, normalized
Examples
Convert into color space value
(to-HSV* :peru)
;;=> [20.950704225352116 176.6341463414634 205.0 255.0]
to-HunterLAB
(to-HunterLAB c)
RGB -> HunterLAB
Returned ranges:
- L: 0.0 - 100.0
- a: -69.08 - 109.48
- b: -199.78 - 55.72
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HunterLAB})
Convert into color space value
(to-HunterLAB :peru)
;;=> [54.87829800912775 19.29580944925891 27.029354768991347 255.0]
to-HunterLAB*
(to-HunterLAB* c)
RGB -> HunterLAB, normalized
Examples
Convert into color space value
(to-HunterLAB* :peru)
;;=> [139.93965992327574 126.20758021200928 226.3654714042049 255.0]
to-HWB
(to-HWB c)
RGB -> HWB
HWB - A More Intuitive Hue-Based Color Model by Alvy Ray Smitch and Eric Ray Lyons, 1995-1996
Ranges:
- H: 0.0 - 360.0
- W: 0.0 - 1.0
- B: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :HWB})
Convert into color space value
(to-HWB :peru)
;;=> [29.577464788732396 0.2470588235294118 0.196078431372549 255.0]
to-HWB*
RGB -> HWB, normalized
Examples
Convert into color space value
(to-HWB* :peru)
;;=> [20.950704225352116 63.00000000000001 49.99999999999999 255.0]
to-IgPgTg
(to-IgPgTg c)
RGB -> IgPgTg
Ranges:
- Ig: 0.0 - 0.97
- Pg: -0.35 - 0.39
- Tg: -0.41 - 0.44
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :IgPgTg})
Convert into color space value
(to-IgPgTg :peru)
;;=> [0.5987969785076355 0.06217862208955094 0.1907217617100152 255.0]
to-IgPgTg*
(to-IgPgTg* c)
RGB -> IgPgTg*, normalized
Examples
Convert into color space value
(to-IgPgTg* :peru)
;;=> [1.5674468689687595E-13 141.85555954119678 181.06105439757565 255.0]
to-IPT
(to-IPT c)
RGB -> IPT
Ranges:
- I: 0.0 - 1.0
- P: -0.45 - 0.66
- T: -0.75 - 0.65
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :IPT})
Convert into color space value
(to-IPT :peru)
;;=> [0.5491769879221229 0.17297511906722254 0.3212682187571702 255.0]
to-IPT*
(to-IPT* c)
RGB -> IPT, normalized
Examples
Convert into color space value
(to-IPT* :peru)
;;=> [140.0418304648625 143.14408677431155 194.85434984340569 255.0]
to-JAB
(to-JAB c)
RGB -> JzAzBz
Jab https://www.osapublishing.org/oe/abstract.cfm?uri=oe-25-13-15131
Ranges:
- J: 0.0 - 0.17
- a: -0.09 - 0.11
- b: -0.156 - 0.115
Reference white point set to 100.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :JAB})
Convert into color space value
(to-JAB :peru)
;;=> [0.10317194697677418 0.028509975958337486 0.07046479892219948 255.0]
to-JAB*
(to-JAB* c)
RGB -> JzAzBz, normalized
Examples
Convert into color space value
(to-JAB* :peru)
;;=> [157.37343827965992 153.302308229718 212.9609396378997 255.0]
to-JCH
(to-JCH c)
RGB -> JCH
Hue based color space derived from JAB
Ranges:
- J: 0.0 - 0.167
- C: 0.0 - 0.159
- H: 0.0 - 360.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :JCH})
Convert into color space value
(to-JCH :peru)
;;=> [0.10317194697677418 0.07601385805424551 67.97180120076064 255.0]
to-JCH*
(to-JCH* c)
RGB -> JCH, normalized
Examples
Convert into color space value
(to-JCH* :peru)
;;=> [157.37343827965992 121.64437718235972 48.146692030245426 255.0]
to-LAB
(to-LAB c)
RGB -> LAB
Returned ranges:
- L: 0.0 - 100.0
- a: -86.18 - 98.25
- b: -107.86 - 94.48
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :LAB})
Convert into color space value
(to-LAB :peru)
;;=> [61.75441860963714 21.39555930166154 47.91832193892602 255.0]
to-LAB*
(to-LAB* c)
RGB -> LAB, normalized
Examples
Convert into color space value
(to-LAB* :peru)
;;=> [157.4737674545747 148.73736828111535 196.31906771299217 255.0]
to-LCH
(to-LCH c)
RGB -> LCH
Returned ranges:
- L: 0.0 - 100.0
- C: 0.0 - 133.82
- H: 0.0 - 360.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :LCH})
Convert into color space value
(to-LCH :peru)
;;=> [61.75441860963714 52.47795284949171 65.93920971405248 255.0]
to-LCH*
(to-LCH* c)
RGB -> LCH, normalized
Examples
Convert into color space value
(to-LCH* :peru)
;;=> [157.4737674545747 100.00218042163684 46.70694711308562 255.0]
to-LCHuv
(to-LCHuv c)
RGB -> LCHuv
Returned ranges:
- L: 0.0 - 100.0
- C: 0.0 - 180.0
- H: 0.0 - 360.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :LCHuv})
Convert into color space value
(to-LCHuv :peru)
;;=> [61.75441860963714 75.16079522246727 40.44454926371432 255.0]
to-LCHuv*
(to-LCHuv* c)
RGB -> LCHuv, normalized
Examples
Convert into color space value
(to-LCHuv* :peru)
;;=> [157.4737674545747 107.04786648153501 28.648227060534108 255.0]
to-linear
(to-linear v)
Gamma correction (gamma=2.4), darken
Examples
Gamma correction
(to-linear 0.5)
;;=> 0.21404114048223255
to-linearRGB
sRGB -> linearRGB
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :linearRGB})
Convert into color space value
(to-linearRGB :peru)
;;=> [155.6763705560055 59.81039845105634 12.675174325952446 255.0]
to-linearRGB*
sRGB -> linearRGB
Examples
Convert into color space value
(to-linearRGB* :peru)
;;=> [155.6763705560055 59.81039845105634 12.675174325952446 255.0]
to-LMS
(to-LMS c)
RGB -> LMS, D65
Ranges: 0.0 - 100.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :LMS})
Convert into color space value
(to-LMS :peru)
;;=> [34.40118955835184 27.693435499312162 7.988162235761204 255.0]
to-LMS*
(to-LMS* c)
RGB -> LMS, normalized
Examples
Convert into color space value
(to-LMS* :peru)
;;=> [87.7207500026746 70.61902673968613 20.37100377523162 255.0]
to-luma-color-hue
(to-luma-color-hue to c)
For given color space return polar representation of the color
to-LUV
(to-LUV c)
RGB -> LUV
Returned ranges:
- L: 0.0 - 100.0
- u: -83.08 - 175.05
- v: -134.12 - 107.40
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :LUV})
Convert into color space value
(to-LUV :peru)
;;=> [61.75441860963714 57.199931444133895 48.75769663612137 255.0]
to-LUV*
(to-LUV* c)
RGB -> LUV, normalized
Examples
Convert into color space value
(to-LUV* :peru)
;;=> [157.4737674545747 138.577201230143 193.08258609954436 255.0]
to-OHTA
(to-OHTA c)
RGB -> OHTA
Returned ranges:
- I1: 0.0 - 255.0
- I2: -127.5 - 127.5
- I3: -127.5 - 127.5
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :OHTA})
Convert into color space value
(to-OHTA :peru)
;;=> [133.66666666666666 71.0 -0.5 255.0]
to-OHTA*
(to-OHTA* c)
RGB -> OHTA, normalized
Examples
Convert into color space value
(to-OHTA* :peru)
;;=> [133.66666666666666 198.5 127.0 255.0]
to-Okhsl
(to-Okhsl c)
sRGB -> Okhsl
Ranges:
- h: 0.0 - 1.0
- s: 0.0 - 1.0
- l: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Okhsl})
Convert into color space value
(to-Okhsl :peru)
;;=> [0.17272662114397214 0.7218843480887962 0.626125151457773 255.0]
to-Okhsl*
(to-Okhsl* c)
RGB -> Okhsl, normalized
Examples
Convert into color space value
(to-Okhsl* :peru)
;;=> [44.04529061139646 181.83605885313455 159.66191483577114 255.0]
to-Okhsv
(to-Okhsv c)
sRGB -> Okhsv
Ranges:
- h: 0.0 - 1.0
- s: 0.0 - 1.0
- v: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Okhsv})
Convert into color space value
(to-Okhsv :peru)
;;=> [0.17272662114397214 0.7404456518525188 0.8179960560123283 255.0]
to-Okhsv*
(to-Okhsv* c)
RGB -> Okhsv, normalized
Examples
Convert into color space value
(to-Okhsv* :peru)
;;=> [44.04529061139642 186.57864001358828 208.5889876168066 255.0]
to-Okhwb
(to-Okhwb c)
sRGB -> Okhwb
Ranges:
- h: 0.0 - 1.0
- w: 0.0 - 1.0
- b: 0.0 - 1.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Okhwb})
Convert into color space value
(to-Okhwb :peru)
;;=> [0.17272662114397214 0.21231443310549042 0.18200394398767172 255.0]
to-Okhwb*
(to-Okhwb* c)
RGB -> Okhwb, normalized
Examples
Convert into color space value
(to-Okhwb* :peru)
;;=> [44.04529061139642 56.502771002982385 46.41101238319341 255.0]
to-Oklab
(to-Oklab c)
RGB -> Oklab
https://bottosson.github.io/posts/oklab/
- L: 0.0 - 1.0
- a: -0.234 - 0.276
- b: -0.312 - 0.199
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Oklab})
Convert into color space value
(to-Oklab :peru)
;;=> [0.6781925733062264 0.05728325697060138 0.10856276795622277 255.0]
to-Oklab*
(to-Oklab* c)
RGB -> Oklab, normalized
Examples
Convert into color space value
(to-Oklab* :peru)
;;=> [172.9391073217668 145.55564012374913 210.00514410562116 255.0]
to-Oklch
(to-Oklch c)
RGB -> Oklch
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Oklch})
Convert into color space value
(to-Oklch :peru)
;;=> [0.6781925733062264 0.12274871125790536 62.181583611829986 255.0]
to-Oklch*
(to-Oklch* c)
RGB -> Oklch, normalized
Examples
Convert into color space value
(to-Oklch* :peru)
;;=> [172.9391073217668 97.0598397774908 44.045302411486276 255.0]
to-OSA
(to-OSA c)
OSA-UCS -> RGB
https://github.com/nschloe/colorio/blob/master/colorio/_osa.py
Ranges:
- L: -13.5 - 7.14
- j (around): -20.0 - 14.0 + some extreme values
- g (around): -20.0 - 12.0 + some extreme values
Note that for some cases (like (to-OSA [18 7 4])
) function returns some extreme values.
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :OSA})
Convert into color space value
(to-OSA :peru)
;;=> [0.14507376477927938 6.789218136248248 -3.7349405564701708 255.0]
to-OSA*
(to-OSA* c)
OSA-UCS -> RGB, normalized
Note that due to some extreme outliers, normalization is triple cubic root for g
and j
.
Examples
Convert into color space value
(to-OSA* :peru)
;;=> [168.62897129000868 223.52938004706834 32.13216364770619 255.0]
to-PalettonHSV
(to-PalettonHSV c)
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :PalettonHSV})
Convert into color space value
(to-PalettonHSV :peru)
;;=> [34.56653534340593 0.6926829268292682 0.803921568627451 255.0]
to-PalettonHSV*
(to-PalettonHSV* c)
Examples
Convert into color space value
(to-PalettonHSV* :peru)
;;=> [24.484629201579203 88.3170731707317 102.5 255.0]
to-RGB
Alias for to-color
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :RGB})
Convert into color space value
(to-RGB :peru)
;;=> [205.0 133.0 63.0 255.0]
to-RGB*
Alias for to-color
Examples
Convert into color space value
(to-RGB* :peru)
;;=> [205.0 133.0 63.0 255.0]
to-RYB
(to-RYB c)
RGB -> RYB
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :RYB})
Convert into color space value
(to-RYB :peru)
;;=> [205.0 201.05555555555557 63.0 255.0]
to-RYB*
RGB -> RYB, normalized
Examples
Convert into color space value
(to-RYB* :peru)
;;=> [205.0 201.05555555555557 63.0 255.0]
to-sRGB
(to-sRGB c)
RGB -> sRGB
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :sRGB})
Convert into color space value
(to-sRGB :peru)
;;=> [231.6145767094841 191.09393296112452 136.21749733111375 255.0]
to-sRGB*
linear RGB -> sRGB
Examples
Convert into color space value
(to-sRGB* :peru)
;;=> [231.6145767094841 191.09393296112452 136.21749733111375 255.0]
to-UCS
(to-UCS c)
sRGB -> UCS
- U: 0.0 - 0.63
- V: 0.0 - 1.0
- W: 0.0 - 1.57
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :UCS})
Convert into color space value
(to-UCS :peru)
;;=> [0.2297609560411064 0.30116275923786345 0.3229215063577835 255.0]
to-UCS*
(to-UCS* c)
sRGB -> UCS, normalized
Examples
Convert into color space value
(to-UCS* :peru)
;;=> [92.463271524323 76.79650360565518 52.476442550398836 255.0]
to-UVW
(to-UVW c)
sRGB -> UVW
- U: -82.15 171.81
- V: -87.16 70.82
- W: -17.0 99.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :UVW})
Convert into color space value
(to-UVW :peru)
;;=> [56.30610204355539 32.00137465257972 60.781043358307215 255.0]
to-UVW*
(to-UVW* c)
sRGB -> UVW, normalized
Examples
Convert into color space value
(to-UVW* :peru)
;;=> [139.02320684769478 192.3380677883153 170.92566159877146 255.0]
to-XYB
(to-XYB c)
sRGB -> XYB
- X: -0.015386116472573375 - 0.02810008316127735
- Y: 0.0 - 0.8453085619621623
- Z: 0.0 - 0.8453085619621623
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :XYB})
Convert into color space value
(to-XYB :peru)
;;=> [0.0093091237938977 0.5304308692924428 0.45483081731562586 255.0]
to-XYB*
(to-XYB* c)
sRGB -> XYB, normalized
Examples
Convert into color space value
(to-XYB* :peru)
;;=> [144.81114286768258 160.01242357654883 137.20653455380022 255.0]
to-XYZ
(to-XYZ c)
sRGB -> XYZ
Returned ranges (D65):
- X: 0.0 - 95.047
- Y: 0.0 - 100.0
- Z: 0.0 - 108.883
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :XYZ})
Convert into color space value
(to-XYZ :peru)
;;=> [34.46414340616597 30.116275923786347 8.699616906363621 255.0]
to-XYZ*
(to-XYZ* c)
sRGB -> XYZ, normalized
Examples
Convert into color space value
(to-XYZ* :peru)
;;=> [92.46327152432293 76.79650360565518 20.37418431823814 255.0]
to-XYZ1
(to-XYZ1 c)
sRGB -> XYZ, scaled to range 0-1
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :XYZ1})
Convert into color space value
(to-XYZ1 :peru)
;;=> [0.34464143406165965 0.30116275923786345 0.08699616906363622 255.0]
to-XYZ1*
sRGB -> XYZ, normalized
Examples
Convert into color space value
(to-XYZ1* :peru)
;;=> [92.46327152432293 76.79650360565518 20.37418431823814 255.0]
to-YCbCr
(to-YCbCr c)
RGB -> YCbCr
Used in JPEG. BT-601
Ranges;
- Y: 0.0 - 255.0
- Cb: -127.5 - 127.5
- Cr: -127.5 - 127.5
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YCbCr})
Convert into color space value
(to-YCbCr :peru)
;;=> [146.511908 -47.14899199999999 41.69184 255.0]
to-YCbCr*
(to-YCbCr* c)
RGB -> YCbCr, normalized
Examples
Convert into color space value
(to-YCbCr* :peru)
;;=> [146.511908 80.35100800000001 169.19184 255.0]
to-YCgCo
(to-YCgCo c)
RGB -> YCgCo
Ranges:
- Y: 0.0 - 255.0
- Cg: -127.5 - 127.5
- Co: -127.5 - 127.5
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YCgCo})
Convert into color space value
(to-YCgCo :peru)
;;=> [133.5 -0.5 71.0 255.0]
to-YCgCo*
(to-YCgCo* c)
RGB -> YCgCo, normalized
Examples
Convert into color space value
(to-YCgCo* :peru)
;;=> [133.5 127.0 198.5 255.0]
to-YDbDr
(to-YDbDr c)
RGB -> YDbDr
Ranges:
- Y: 0.0 - 255.0
- Db: -340.0 - 340.0
- Dr: -340.0 - 340.0
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YDbDr})
Convert into color space value
(to-YDbDr :peru)
;;=> [146.54799999999997 -125.71000000000002 -111.16599999999997 255.0]
to-YDbDr*
(to-YDbDr* c)
RGB -> YDbDr
Examples
Convert into color space value
(to-YDbDr* :peru)
;;=> [146.54799999999997 80.34696174043509 85.80232558139537 255.0]
to-YIQ
(to-YIQ c)
RGB -> YIQ
Ranges:
- Y: 0.0 - 255.0
- I: -151.9 - 151.9
- Q: -133.26 - 133.26
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YIQ})
Convert into color space value
(to-YIQ :peru)
;;=> [146.511908 65.37996199999999 -6.554618000000001 255.0]
to-YIQ*
(to-YIQ* c)
RGB -> YIQ, normalized
Examples
Convert into color space value
(to-YIQ* :peru)
;;=> [146.511908 182.37510995172195 121.22873049861172 255.0]
to-YPbPr
(to-YPbPr c)
RGB -> YPbPr
Ranges:
- Y: 0.0 - 255.0
- Pb: -236.6 - 236.6
- Pr: -200.8 - 200.8
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YPbPr})
Convert into color space value
(to-YPbPr :peru)
;;=> [143.2532 -80.25319999999999 61.74680000000001 255.0]
to-YPbPr*
(to-YPbPr* c)
RGB -> YPbPr, normalized
Examples
Convert into color space value
(to-YPbPr* :peru)
;;=> [143.2532 84.25080836387153 166.70929641859286 255.0]
to-YUV
(to-YUV c)
RGB -> YUV
Ranges:
- Y: 0.0 - 255.0
- u: -111.2 - 111.2
- v: -156.8 - 156.8
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :YUV})
Convert into color space value
(to-YUV :peru)
;;=> [146.511908 -41.104 51.28 255.0]
to-YUV*
(to-YUV* c)
RGB -> YUV, normalized
Examples
Convert into color space value
(to-YUV* :peru)
;;=> [146.511908 80.36238532110092 169.19105691056913 255.0]
to-Yxy
(to-Yxy c)
sRGB -> Yxy
Returned ranges:
- Y: 0.0 - 100.0
- x: 0.15 - 0.64
- y: 0.06 - 0.60
Examples
Gradient between four colors using given color space.
(clojure2d.color/gradient [:maroon :white :black :lightcyan]
{:colorspace :Yxy})
Convert into color space value
(to-Yxy :peru)
;;=> [30.116275923786347 0.4703074012548907 0.41097517783242304 255.0]
to-Yxy*
(to-Yxy* c)
sRGB -> Yxy, normalized
Examples
Convert into color space value
(to-Yxy* :peru)
;;=> [76.79650360565518 187.36629473878304 174.66445057877976 255.0]
valid-color?
(valid-color? c)
Check if given argument is valid color.
Check is done by trying to convert to color representation.
Returns color when valid.
See also possible-color?
Examples
Usage
(valid-color? :blue)
;;=> [0.0 0.0 255.0 255.0]
(valid-color? :not-a-color)
;;=> nil
(valid-color? [1 2 3 255])
;;=> [1.0 2.0 3.0 255.0]
(valid-color? [:red :green :blue])
;;=> false
(valid-color? (gradient [:red :blue]))
;;=> false
weighted-average
(weighted-average cs weights colorspace)
(weighted-average cs weights)
Average colors with weights in given colorspace
(default: :sRGB
)
whiten
(whiten col)
(whiten col amt)
Change color towards white.
Works in HSB color space. Default amount is set to 0.2 and changes W channel by this amount.
See blacken.