xXMADEXx Posted August 6, 2014 Share Posted August 6, 2014 Hey guys. So, I'm writing a basic function for bordered text, but I can't figure out how to get RGBA from the tocolor number that is sent in the color argument. I'm trying to make it so that the back texts will have the same alpha as the main text. Thanks in advance. Link to comment
tosfera Posted August 6, 2014 Share Posted August 6, 2014 You know you can use tocolor also with rgba, right? All you have to to do is; tocolor ( r, g, b, a ) Or isn't that what you want? Link to comment
cheez3d Posted August 6, 2014 Share Posted August 6, 2014 tocolor() converts your numbers to Hex and then it converts that Hex back to one decimal number. tocolor(255,255,255) => 0xFFFFFF => 16777215 (without alpha); tocolor(255,255,255,255) => 0xFFFFFFFF => 4294967295 (with alpha); To get the Hex back from the decimal number just format the string "%x" like this: ("%x"):format(tocolor(r,g,b)) And that is your Hex. If you want to go deeper and convert that Hex back to 3 or 4 decimals you do it like this: local Hex = ("%x"):format(tocolor(r,g,b)); local Color = {}; for i = 1,6,2 do table.insert(Color,tonumber(Hex:sub(i,i+1),16)); -- supply 16 as an argument because we are converting from base 16; end; And that is your RGB. Link to comment
ixjf Posted August 6, 2014 Share Posted August 6, 2014 local color = tocolor ( 0, 0, 0, 255 ) local r = bitExtract ( color, 0, 8 ) local g = bitExtract ( color, 8, 8 ) local b = bitExtract ( color, 16, 8 ) local a = bitExtract ( color, 24, 8 ) tocolor() converts your numbers to Hex and then it converts that Hex back to one decimal number. No, it does not. tonumber does, which is why you see it as a decimal number. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now