-- Function decToHex (renamed, updated): http://lua-users.org/lists/lua-l/2004-09/msg00054.html local 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 return OUT end -- Function rgbToHex: http://gameon365.net/index.php local function rgbToHex(c) local output = decToHex(c["r"]) .. decToHex(c["g"]) .. decToHex(c["b"]); return output end
Usage
local rgbcolor = {}; local rgbcolor["r"] = 214; local rgbcolor["g"] = 42; local rgbcolor["b"] = 172; local hexcolor = rgbToHex(rgbcolor);