You are not logged in.
I have searched for this off and on for quite a while now ... to no avail.
Does anyone know of a "cairo" colour code chart?
Or have a way to convert HEX / Decimal Codes to the format that cairo uses?
HEX/Decimal Chart
Hex Decimal colours
code code HTML name
& rgb(a)
{snip}
FFEBCD #255 235 205 BlanchedAlmond
FFE4C4 #255 228 196 Bisque
FFDEAD #255 222 173 NavajoWhite
F5DEB3 #245 222 179 Wheat
DEB887 #222 184 135 BurlyWood
{snip}
EXAMPLE (if there is no chart somewhere):
How would I convert FFDEAD #255 222 173 NavajoWhite to:
cairo_set_source_rgba(cr,?.?,?.?,?.?,1)
FF (255) to (cr,0.0,g.g,b.b,a)
DE (222) to (cr,r.r,0.0,b.b,a)
AD (173) to (cr,r.r,g.g,0.0,a)
Not worried about the ALPHA setting - that I get.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
It's actually quite simple. You need to map the value range of an unsigned 8-bit wide integer (0-255) to a double in the range 0.0-1.0. Take the value of every byte in the hexstring and divide by 255.
Here's a simple script that's going to help you:
#!/usr/bin/env python3
import sys
if __name__ == "__main__":
n = int(sys.argv[1], 16)
print("#{} => rgb({:.2f}, {:.2f}, {:.2f})".format(sys.argv[1], (n>>16)/255, (n>>8&~(0xFF<<8))/255, (n & ~(0xFFFF<<8))/255))
Save as map.py, then pass your hex numbers as arguments, i.e.
$ python3 map.py ffdead
#ffdead => rgb(1.00, 0.87, 0.68)
Offline
AWESOME!!!!!!!!!!!!! THANK YOU nobody!
I can't believe it's a simple division thing ... had I only known.
Renamed it with a slight mod: rgb
#!/usr/bin/env python3
# By: nobody - BunsenLabs - 27 Mar 2016
# https://forums.bunsenlabs.org/viewtopic.php?pid=22917#p22917
# USAGE:
# $ rgb ffdead
# #ffdead => rgb(1.00, 0.87, 0.68)
import sys
if __name__ == "__main__":
n = int(sys.argv[1], 16)
print("#{} => rgb({:.2f}, {:.2f}, {:.2f})".format(sys.argv[1], (n>>16)/255, (n>>8&~(0xFF<<8))/255, (n & ~(0xFFFF<<8))/255))
BONUS: UPPER / lower or Mixed case
27 Mar 16 @ 14:31:24 ~
$ rgb a0a0a0
#a0a0a0 => rgb(0.63, 0.63, 0.63)
27 Mar 16 @ 14:34:29 ~
$ rgb A0A0A0
#A0A0A0 => rgb(0.63, 0.63, 0.63)
27 Mar 16 @ 14:34:42 ~
$ rgb BCa0a0
#BCa0a0 => rgb(0.74, 0.63, 0.63)
27 Mar 16 @ 14:35:59 ~
$
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline
Now I can change some fugly** colours in some LUA scripts I have
** freakin' ugly ...
... and you can quote me on that.
Debian 12 Beardog, SoxDog and still a Conky 1.9er
Offline