You are not logged in.

#1 2016-03-27 15:05:20

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

[SOLVED] Cairo colour codes (used in LUA)

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.  smile


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

#2 2016-03-27 16:31:15

nobody
The Great
Registered: 2015-08-10
Posts: 3,655

Re: [SOLVED] Cairo colour codes (used in LUA)

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

#3 2016-03-27 17:37:11

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: [SOLVED] Cairo colour codes (used in LUA)

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

#4 2016-03-27 17:41:56

Sector11
Mod Squid Tpyo Knig
From: Upstairs
Registered: 2015-08-20
Posts: 8,008

Re: [SOLVED] Cairo colour codes (used in LUA)

Now I can change some fugly** colours in some LUA scripts I have  smile


** freakin' ugly ...  wink
... and you can quote me on that. lol


Debian 12 Beardog, SoxDog and still a Conky 1.9er

Offline

Board footer

Powered by FluxBB