Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Entire forum
➜ MUSHclient
➜ Lua
➜ color code: RGB number to hex
color code: RGB number to hex
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Zimmy
(31 posts) Bio
|
Date
| Sat 28 Dec 2019 05:00 PM (UTC) Amended on Sat 28 Dec 2019 05:18 PM (UTC) by Zimmy
|
Message
| I would like to be able to convert RGB color codes into hex format.
I've tried this:
--works for black and white
print("#"..string.format("%06x", ColourNameToRGB("white"))) --> "#ffffff"
print("#"..string.format("%06x", ColourNameToRGB("black"))) --> "#000000"
--but for red, I get blue!
print("#"..string.format("%06x", ColourNameToRGB("red"))) --> "#0000ff"
Thanks!
[EDIT] okay so I figured out rgb color codes are actually bgr [/edit]
--this works :)
local function rgb_to_hex(col)
local b, g, r = string.match(string.format("%06x", col), "([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])([0-9a-f][0-9a-f])")
return "#"..r..g..b
end
print(rgb_to_hex(ColourNameToRGB("yellow"))) -- > "#ffff00"
| Top |
|
Posted by
| Nick Gammon
Australia (23,120 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 28 Dec 2019 09:09 PM (UTC) |
Message
| |
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
9,466 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top