Buffalo Posted February 9, 2011 Share Posted February 9, 2011 I need to change HEX to RGB. I don't know how it works nor how it can be worked out, need a helping hand here. Link to comment
proracer Posted February 9, 2011 Share Posted February 9, 2011 I didn't understood you quite well there. Maybe try this or...? http://www.javascripter.net/faq/hextorgb.htm Link to comment
Buffalo Posted February 9, 2011 Author Share Posted February 9, 2011 Nevermind, i found it myself. Like: #1DFFAA R = 16(1+13/16) = 29 G= 16(15+15/16) = 255 B = 16(10+10/16) = 170 Link to comment
Aibo Posted February 9, 2011 Share Posted February 9, 2011 function hex2rgb(hex) hex = hex:gsub("#","") return tonumber("0x"..hex:sub(1,2)), tonumber("0x"..hex:sub(3,4)), tonumber("0x"..hex:sub(5,6)) end EDIT: https://wiki.multitheftauto.com/wiki/GetColorFromString Link to comment
norby89 Posted February 9, 2011 Share Posted February 9, 2011 Just in case anyone needs the opposite of this function: function rgbToHex ( nR, nG, nB ) local sColor = "#" nR = string.format ( "%X", nR ) sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR ) nG = string.format ( "%X", nG ) sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG ) nB = string.format ( "%X", nB ) sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB ) return sColor end Link to comment
Aibo Posted February 9, 2011 Share Posted February 9, 2011 Just in case anyone needs the opposite of this function: function rgbToHex ( nR, nG, nB ) local sColor = "#" nR = string.format ( "%X", nR ) sColor = sColor .. ( ( string.len ( nR ) == 1 ) and ( "0" .. nR ) or nR ) nG = string.format ( "%X", nG ) sColor = sColor .. ( ( string.len ( nG ) == 1 ) and ( "0" .. nG ) or nG ) nB = string.format ( "%X", nB ) sColor = sColor .. ( ( string.len ( nB ) == 1 ) and ( "0" .. nB ) or nB ) return sColor end eh function rgb2hex(r,g,b) return string.format("#%02X%02X%02X", r,g,b) end Link to comment
Deltanic Posted February 10, 2011 Share Posted February 10, 2011 hmm tocolor(r,g,b) ? Link to comment
Aibo Posted February 10, 2011 Share Posted February 10, 2011 tocolor() does not return hex color value as i recall. it's decimal with alpha. 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