Mothback/data/scripts/hex.lua

31 lines
874 B
Lua
Raw Normal View History

function HEX2RGB(color)
local r1 = HEX2DEX(color:sub(2,2))
local r2 = HEX2DEX(color:sub(3,3))
local g1 = HEX2DEX(color:sub(4,4))
local g2 = HEX2DEX(color:sub(5,5))
local b1 = HEX2DEX(color:sub(6,6))
local b2 = HEX2DEX(color:sub(7,7))
return {(r1*16 + r2)/255, (g1*16 + g2)/255, (b1*16 + b2)/255}
end
function HEX2DEX(hex)
if hex == "0" then return 0
elseif hex == "1" then return 1
elseif hex == "2" then return 2
elseif hex == "3" then return 3
elseif hex == "4" then return 4
elseif hex == "5" then return 5
elseif hex == "6" then return 6
elseif hex == "7" then return 7
elseif hex == "8" then return 8
elseif hex == "9" then return 9
elseif hex == "a" then return 10
elseif hex == "b" then return 11
elseif hex == "c" then return 12
elseif hex == "d" then return 13
elseif hex == "e" then return 14
elseif hex == "f" then return 15
end
end