'LinKin Posted March 4, 2014 Share Posted March 4, 2014 Hello, I found this on the internet, and made a little change because it wasn't working properly when R or G or B were 0. function decToHex(IN) local B,K,OUT,I,D=16,"0123456789ABCDEF","",0 while IN>0 do I=I+1 IN,D=math.floor(IN/B),math.fmod(IN,B)+1 OUT=string.sub(K,D,D)..OUT end if I > 0 then return OUT else return "00" end end function rgbToHex(r, g, b) local output = decToHex® .. decToHex(g) .. decToHex(b); return output end But now, I've noticed another problem.. If R or G or B are < 10 it fails.. For example when I try to convert R: 9 G: 255 B: 255 It returns this hex code: 9FFFF which is wrong.... Idk how to fix it Link to comment
'LinKin Posted March 4, 2014 Author Share Posted March 4, 2014 Yes, damn. Just found that function. Thank you. 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