Jump to content

Convert RGB into Hex Colorcode


'LinKin

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...