A collection of tools aimed at those working with color, useful for CSS, Emacs themes, etc.
Use rainbow-mode when using kurecolor commands, for instant feedback on color changes.
Visit the main repository at https://github.com/emacsfodder/kurecolor
Kurecolor is on MELPA, you can install using package.el
M-x package-install kurecolor
(color &optional hue-groups)
(num min max)
(n)
(color1 color2)
(hex)
(hex)
(cssrgb &optional hexrgba)
(value)
(hex hue)
(hex sat)
(hex val)
(source target)
(source target)
(source target)
(hex)
(hex)
(hex)
(h s v)
(h s v)
(rgb)
(hex)
(hex)
(hex)
(hex amount)
(hex amount)
(hex amount)
(rgba)
(color &optional hue-groups)
Return the color hue group for color
.
Optionally provide a list of hue-groups
, (default uses kurecolor-hue-groups
.)
Also available is kurecolor-simple-hue-groups
,
both are customizable, or define your own.
This facilitates hue grouping & sorting by a secondary axis.
For example sort a list of colors by some axis (brightness or saturation). Then group by hue groups, and sort the groups.
The format of each group in the list is:
(group-name (n1 . n2))
Where group-name
is a symbol to name the group,
(n1 . n2)
is a hue range specifier (in degrees)
low n1
to high n2
.
a
hue range which crosses the apex (i.e. 360°..0°
) is permitted.
(kurecolor-hue-group "#00FF00" '((group-a (340 . 120)) (group-b (120 . 240)) (group-c (240 . 340))))
⇒ 'group-b
(kurecolor-hue-group "#FFFF00" kurecolor-hue-ranges)
⇒ 'yellow-green
(kurecolor-hue-group "#FF0000")
⇒ 'red
(num min max)
Clamp num
to range of min
max
.
(kurecolor-clamp 1 -1.0 1.0)
⇒ 1
(kurecolor-clamp 2 -1.0 1.0)
⇒ 1.0
(kurecolor-clamp -2 -1.0 1.0)
⇒ -1.0
(n)
Convert n
(0.0..1.0
) to 0-255
.
(kurecolor-to-8bit 0)
⇒ 0.0
(kurecolor-to-8bit 1)
⇒ 255.0
(kurecolor-to-8bit 0.3231)
⇒ 82.3905
(color1 color2)
Interpolate two hex colors color1
and color2
, to get their mixed color.
(kurecolor-interpolate "#FFFFFF" "#000000")
⇒ "#7F7F7F"
(kurecolor-interpolate "#0077FF" "#111111")
⇒ "#084488"
(kurecolor-interpolate "#FF7700" "#111111")
⇒ "#884408"
(hex)
Convert a hex
rgb color to css rgb.
(kurecolor-hex-to-cssrgb "#347291")
⇒ "rgb(52, 114, 145)"
(kurecolor-hex-to-cssrgb "#000000")
⇒ "rgb(0, 0, 0)"
(kurecolor-hex-to-cssrgb "#888888")
⇒ "rgb(136, 136, 136)"
(hex)
Convert a hex
rgba color to css rgba.
(kurecolor-hex-to-cssrgba "#347291FF")
⇒ "rgba(52, 114, 145, 1.0000)"
(kurecolor-hex-to-cssrgba "#34729100")
⇒ "rgba(52, 114, 145, 0.0000)"
(kurecolor-hex-to-cssrgba "#34729180")
⇒ "rgba(52, 114, 145, 0.5020)"
(cssrgb &optional hexrgba)
Convert a cssrgb
(rgb()
or rgba()
) color to hex.
When hexrgba
is non-nil the hex color string will be rgba
.
If css alpha
value isn’t present, it will be set as 1.0
i.e. no transparency
Valid css rgb()
rgba()
values are supported.
(kurecolor-cssrgb-to-hex "rgb(10%, 20%, 90%)")
⇒ "#1933E5"
(kurecolor-cssrgb-to-hex "rgba(100%, 100%, 100%, 1.0)")
⇒ "#FFFFFF"
(kurecolor-cssrgb-to-hex "rgb(52, 114, 145)")
⇒ "#347291"
(value)
Convert css rgb()
or rgba()
: r
, g
, b
value
.
From number 0-255
or percentage, to 0-255
.
(kurecolor-css-rgb-value-to-number "10")
⇒ 10
(kurecolor-css-rgb-value-to-number "10%")
⇒ 25.5
(kurecolor-css-rgb-value-to-number "100%")
⇒ 255.0
(hex hue)
Change a hex
color’s hue
, amount values from 0.0..1.0
.
returns a rgb
hex color.
(kurecolor-hex-set-hue "#FF7700" 0.5)
⇒ "#00FFFF"
(kurecolor-hex-set-hue "#FF00FF" 0.5)
⇒ "#00FFFF"
(kurecolor-hex-set-hue "#FFFF00" 0.5)
⇒ "#00FFFF"
(hex sat)
Change a hex
color’s saturation sat
, amount values from 0.0..1.0
.
returns a rgb
hex color.
(kurecolor-hex-set-saturation "#FF7700" 0.5)
⇒ "#FFBB7F"
(kurecolor-hex-set-saturation "#007700" 0.5)
⇒ "#3B773B"
(kurecolor-hex-set-saturation "#FF0000" 0.5)
⇒ "#FF7F7F"
(hex val)
Change a hex
color’s brightness val
, amount values from 0.0..1.0
.
returns a rgb
hex color.
(kurecolor-hex-set-brightness "#FF7700" 0.5)
⇒ "#7F3B00"
(kurecolor-hex-set-brightness "#FF0000" 0.5)
⇒ "#7F0000"
(kurecolor-hex-set-brightness "#FF0077" 0.5)
⇒ "#7F003B"
(source target)
Copy brightness from source
to target
.
(kurecolor-hex-set-brightness-from "#008800" "#000000")
⇒ "#888888"
(kurecolor-hex-set-brightness-from "#00FF00" "#000000")
⇒ "#FFFFFF"
(kurecolor-hex-set-brightness-from "#000000" "#00FF00")
⇒ "#000000"
(source target)
Copy brightness from source
to target
.
(kurecolor-hex-set-hue-from "#FF0000" "#00FF00")
⇒ "#FF0000"
(kurecolor-hex-set-hue-from "#00FF00" "#FF0000")
⇒ "#00FF00"
(kurecolor-hex-set-hue-from "#0088FF" "#880000")
⇒ "#004888"
(source target)
Copy the saturation of source
to target
.
(kurecolor-hex-set-saturation-from "#000000" "#00FF00")
⇒ "#FFFFFF"
(kurecolor-hex-set-saturation-from "#004400" "#00FF00")
⇒ "#00FF00"
(kurecolor-hex-set-saturation-from "#FFBB7F" "#FF7700")
⇒ "#FFBA7F"
(hex)
Convert a rgb
hex
color to a list (r g b)
.
The r
,g
,b
values range between 0.0..1.0
.
(kurecolor-hex-to-rgb "#347291")
⇒ '(0.20392156862745098 0.4470588235294118 0.5686274509803921)
(kurecolor-hex-to-rgb "#72FF91")
⇒ '(0.4470588235294118 1.0 0.5686274509803921)
(kurecolor-hex-to-rgb "#720091")
⇒ '(0.4470588235294118 0.0 0.5686274509803921)
(hex)
Convert a rgba
hex
color to a list (r g b a)
.
rgba
hex
colors = #
rrggbbaa`` (i.e. css
hex rgba)
e.g. #
ffffff00`` white with no opacity.
#000000FF
black with no transparency.
The returned list (rgba)
values will range between 0.0..1.0
.
(kurecolor-hex-to-rgba "#34729100")
⇒ '(0.20392156862745098 0.4470588235294118 0.5686274509803921 0.0)
(kurecolor-hex-to-rgba "#FFFFFFFF")
⇒ '(1.0 1.0 1.0 1.0)
(kurecolor-hex-to-rgba "#72009172")
⇒ '(0.4470588235294118 0.0 0.5686274509803921 0.4470588235294118)
(hex)
Convert a rgb
hex
color to h
s
v
.
(kurecolor-hex-to-hsv "#347291")
⇒ '(0.5555555555555556 0.6413793103448275 0.5686274509803921)
(kurecolor-hex-to-hsv "#729134")
⇒ '(0.2222222222222222 0.6413793103448275 0.5686274509803921)
(kurecolor-hex-to-hsv "#913472")
⇒ '(0.8888888888888888 0.6413793103448275 0.5686274509803921)
(h s v)
Convert h
s
v
to a rgb
hex color.
(kurecolor-hsv-to-hex 0.5555555555555556 0.65 0.5686274509803921)
⇒ "#327191"
(kurecolor-hsv-to-hex 1.0 0.7 1.0)
⇒ "#FF4C4C"
(kurecolor-hsv-to-hex 0.5 0.5 0.6)
⇒ "#4C9999"
(h s v)
Convert hsv (h
s
v
) to red green blue.
Note: args h
s
v
are expected to be a values from 0.0..1.0
(kurecolor-hsv-to-rgb 0.5555555555555556 0.6413793103448275 0.5686274509803921)
⇒ '(0.203921568627451 0.4470588235294117 0.5686274509803921)
(rgb)
rgb
as a list (r g b)
to rgb
hex color.
The r
,g
,b
values can range between 0.0..1.0
.
(kurecolor-rgb-to-hex '(0.20392156862745098 0.4470588235294118 0.5686274509803921))
⇒ "#347291"
(hex)
Get the brightness of hex
color.
(kurecolor-hex-get-brightness "#FFFFFF")
⇒ 1.0
(kurecolor-hex-get-brightness "#808080")
⇒ 0.5019607843137255
(kurecolor-hex-get-brightness "#000000")
⇒ 0.0
(hex)
Get the saturation of hex
color.
(kurecolor-hex-get-saturation "#00FF00")
⇒ 1.0
(kurecolor-hex-get-saturation "#7FFF7F")
⇒ 0.5019607843137255
(kurecolor-hex-get-saturation "#000000")
⇒ 0.0
(hex)
Get the hue of hex
color.
(kurecolor-hex-get-hue "#FF0000")
⇒ 0.0
(kurecolor-hex-get-hue "#00FF00")
⇒ 0.3333333333333333
(kurecolor-hex-get-hue "#0000FF")
⇒ 0.6666666666666666
(hex amount)
Adjust the hex
color saturation by amount
-1.0..1.0
.
(kurecolor-adjust-saturation "#006091" -0.1)
⇒ "#0E6491"
(kurecolor-adjust-saturation "#006091" -0.2)
⇒ "#1C6991"
(kurecolor-adjust-saturation "#006091" -0.5)
⇒ "#487891"
(hex amount)
Adjust the hex
color brightness by amount
-1.0..1.0
.
(kurecolor-adjust-brightness "#FFFFFF" -0.1)
⇒ "#E5E5E5"
(kurecolor-adjust-brightness "#FFFFFF" -0.2)
⇒ "#CCCCCC"
(kurecolor-adjust-brightness "#FFFFFF" -0.5)
⇒ "#7F7F7F"
(hex amount)
Adjust the hex
color hue by amount
0.0..1.0
.
(kurecolor-adjust-hue "#FF0000" -0.1)
⇒ "#FF0098"
(kurecolor-adjust-hue "#FF7700" -0.2)
⇒ "#FF00BB"
(kurecolor-adjust-hue "#FFFF00" -0.5)
⇒ "#0000FF"
(rgba)
Convert a hex rgba
string to an XCode colorLiteral
.
(kurecolor-hex-rgba-to-xcode-color-literal "#0E1B21FF")
⇒ "#colorLiteral(red: 0.0549019608, green: 0.1058823529, blue: 0.1294117647, alpha: 1.0000000000)"
(kurecolor-hex-rgba-to-xcode-color-literal "#ECF3F600")
⇒ "#colorLiteral(red: 0.9254901961, green: 0.9529411765, blue: 0.9647058824, alpha: 0.0000000000)"
(kurecolor-hex-rgba-to-xcode-color-literal "#ADC3CC80")
⇒ "#colorLiteral(red: 0.6784313725, green: 0.7647058824, blue: 0.8000000000, alpha: 0.5019607843)"
(kurecolor-xcode-color-literal-to-hex-rgba "#colorLiteral(red: 0.0864074271, green: 0.1963072013, blue: 0.2599330357, alpha: 1)")
⇒ "#163242FF"
(kurecolor-xcode-color-literal-to-hex-rgba "#colorLiteral(red: 0.0585, green: 0.10855, blue: 0.13, alpha: 1)")
⇒ "#0E1B21FF"
(kurecolor-xcode-color-literal-to-hex-rgba "#colorLiteral(red: 0.9280523557, green: 0.9549868208, blue: 0.9678013393, alpha: 1)")
⇒ "#ECF3F6FF"
(kurecolor-xcode-color-literal-to-hex-rgb "#colorLiteral(red: 0.05882352941, green: 0.1098039216, blue: 0.0, alpha: 1)")
⇒ "#0E1C00"
(kurecolor-xcode-color-literal-to-hex-rgb "#colorLiteral(red: 0.0585, green: 0.10855, blue: 0.13, alpha: 1)")
⇒ "#0E1B21"
(kurecolor-xcode-color-literal-to-hex-rgb "#colorLiteral(red: 0.9280523557, green: 0.9549868208, blue: 0.9678013393, alpha: 1)")
⇒ "#ECF3F6"
The examples documented here are live tests (in kurecolor-examples.el
). You can
run them using bin/test
from the package folder.`