Hi all, Please consider donating to this or any of my many of opensource projects.
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.
Kurecolor is on MELPA, you can install using package.el
M-x package-install kurecolor
- kurecolor-hue-group
(color &optional hue-groups)
- kurecolor-clamp
(num min max)
- kurecolor-to-8bit
(n)
- kurecolor-interpolate
(color1 color2)
- kurecolor-hex-to-cssrgb
(hex)
- kurecolor-hex-to-cssrgba
(hex)
- kurecolor-cssrgb-to-hex
(cssrgb &optional hexrgba)
- kurecolor-css-rgb-value-to-number
(value)
- kurecolor-hex-set-hue
(hex hue)
- kurecolor-hex-set-saturation
(hex sat)
- kurecolor-hex-set-brightness
(hex val)
- kurecolor-hex-set-brightness-from
(source target)
- kurecolor-hex-set-hue-from
(source target)
- kurecolor-hex-set-saturation-from
(source target)
- kurecolor-hex-to-rgb
(hex)
- kurecolor-hex-to-rgba
(hex)
- kurecolor-hex-to-hsv
(hex)
- kurecolor-hsv-to-hex
(h s v)
- kurecolor-hsv-to-rgb
(h s v)
- kurecolor-rgb-to-hex
(rgb)
- kurecolor-hex-get-brightness
(hex)
- kurecolor-hex-get-saturation
(hex)
- kurecolor-hex-get-hue
(hex)
- kurecolor-adjust-saturation
(hex amount)
- kurecolor-adjust-brightness
(hex amount)
- kurecolor-adjust-hue
(hex amount)
- kurecolor-hex-rgba-to-xcode-color-literal
(rgba)
- kurecolor-xcode-literal-to-hex-rgba
- kurecolor-xcode-literal-to-hex-rgb
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-groups)
⇒ 'yellow-green
(kurecolor-hue-group "#FF0000")
⇒ 'red
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
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.39
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"
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)"
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)"
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"
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
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"
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"
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"
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"
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"
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"
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.2039 0.4471 0.5686)
(kurecolor-hex-to-rgb "#72FF91")
⇒ '(0.4471 1.0 0.5686)
(kurecolor-hex-to-rgb "#720091")
⇒ '(0.4471 0.0 0.5686)
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.2039 0.4471 0.5686 0.0)
(kurecolor-hex-to-rgba "#FFFFFFFF")
⇒ '(1.0 1.0 1.0 1.0)
(kurecolor-hex-to-rgba "#72009172")
⇒ '(0.44715 0.0 0.5686 0.4471)
Convert a rgb
hex
color to h
s
v
.
(kurecolor-hex-to-hsv "#347291")
⇒ '(0.5556 0.6414 0.5686)
(kurecolor-hex-to-hsv "#729134")
⇒ '(0.2222 0.6414 0.5686)
(kurecolor-hex-to-hsv "#913472")
⇒ '(0.8889 0.6414 0.5686)
Convert h
s
v
to a rgb
hex color.
(kurecolor-hsv-to-hex 0.556 0.65 0.5687)
⇒ "#327191"
(kurecolor-hsv-to-hex 1.0 0.7 1.0)
⇒ "#FF4C4C"
(kurecolor-hsv-to-hex 0.5 0.5 0.6)
⇒ "#4C9999"
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.5555 0.6413 0.5686)
⇒ '(0.2039 0.4472 0.5686)
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.204 0.44706 0.5687))
⇒ "#347291"
Get the brightness of hex
color.
(kurecolor-hex-get-brightness "#FFFFFF")
⇒ 1.0
(kurecolor-hex-get-brightness "#808080")
⇒ 0.502
(kurecolor-hex-get-brightness "#000000")
⇒ 0.0
Get the saturation of hex
color.
(kurecolor-hex-get-saturation "#00FF00")
⇒ 1.0
(kurecolor-hex-get-saturation "#7FFF7F")
⇒ 0.502
(kurecolor-hex-get-saturation "#000000")
⇒ 0.0
Get the hue of hex
color.
(kurecolor-hex-get-hue "#FF0000")
⇒ 0.0
(kurecolor-hex-get-hue "#00FF00")
⇒ 0.3333
(kurecolor-hex-get-hue "#0000FF")
⇒ 0.6667
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"
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"
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"
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.`
For those interested in such things, the name Kurecolor is unashamedly nicked from a high end marker pen company. Hopefully this outrage will fall silently under their radar, and I won't have to change it due to some frivilous and paranoid law suit. (seriously guys, this is just free advertising.)
I have not been pressured into saying this, however, Kurecolor markers and art supplies are the very best! Buy some (many!) NOW (Like REALLY Immediately!!) for you, your mum and your pet chinchilla Frank.
Since the question comes up occassionally, the mode-line hack used in the presentation is based on original work by Armit Patel. I gisted this a while back, you can get it from. https://gist.github.com/jasonm23/8554119