Module:Color contrast: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(add shorthand)
(refactor to allow this to be called from another module)
Line 120: Line 120:
-- failure, return blank
-- failure, return blank
return ''
return ''
end

local function colors2ratio(c1,c2)
local v1 = color2lum(c1)
local v2 = color2lum(c2)
if (type(v1) == 'number' and type(v2) == 'number') then
return (v2 + 0.05)/(v1 + 0.05)
else
return ''
end
end
end


Line 127: Line 137:


function p.ratio(frame)
function p.ratio(frame)
local r = colors2ratio(
local v1 = color2lum(frame.args[1] or frame:getParent().args[1])
local v2 = color2lum(frame.args[2] or frame:getParent().args[2])
frame.args[1] or frame:getParent().args[1],
frame.args[2] or frame:getParent().args[2]
if (type(v1) == 'number' and type(v2) == 'number') then
)
return (v2 + 0.05)/(v1 + 0.05)
if (r ~= '') then
return r
else
else
return frame.args['error'] or frame:getParent().args['error'] or '?'
return frame.args['error'] or frame:getParent().args['error'] or '?'