Changed ColorToHex to just use string.format instead of useless number to hexstring to number to hexstring conversion.
This commit is contained in:
@@ -191,8 +191,6 @@ end
|
||||
|
||||
-- ColorToHex(c)
|
||||
-- Takes in a normal color("") and returns the hex representation.
|
||||
-- Adapted from code in LuaBit (http://luaforge.net/projects/bit/),
|
||||
-- which is MIT licensed and copyright (C) 2006~2007 hanzhao.
|
||||
function ColorToHex(c)
|
||||
local r = c[1]
|
||||
local g = c[2]
|
||||
@@ -200,27 +198,7 @@ function ColorToHex(c)
|
||||
local a = HasAlpha(c)
|
||||
|
||||
local function hex(value)
|
||||
value = math.ceil(value)
|
||||
|
||||
local hexVals = { 'A', 'B', 'C', 'D', 'E', 'F' }
|
||||
local out = ""
|
||||
local last = 0
|
||||
|
||||
while(value ~= 0) do
|
||||
last = math.mod(value, 16)
|
||||
if(last < 10) then
|
||||
out = tostring(last) .. out
|
||||
else
|
||||
out = hexVals[(last-10)+1] .. out
|
||||
end
|
||||
value = math.floor(value/16)
|
||||
end
|
||||
|
||||
if(out == "") then
|
||||
return "00"
|
||||
end
|
||||
|
||||
return string.format( "%02X", tonumber(out,16) )
|
||||
return ("%02X"):format(value)
|
||||
end
|
||||
|
||||
local rX = hex( scale(r, 0, 1, 0, 255) )
|
||||
|
||||
Reference in New Issue
Block a user