Module:Color contrast: Difference between revisions

refactor to allow this to be called from another module
(add shorthand)
(refactor to allow this to be called from another module)
Line 120:
-- failure, return blank
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
 
Line 127 ⟶ 137:
 
function p.ratio(frame)
local r = colors2ratio(
local v1 = color2lum(frame.args[1] or frame:getParent().args[1])
local v2 = color2lum( frame.args[21] or frame:getParent().args[21]),
local v1 = color2lum( frame.args[12] or frame:getParent().args[12])
if (type(v1) == 'number' and type(v2) == 'number') then
)
return (v2 + 0.05)/(v1 + 0.05)
if (r ~= '') then
return r
else
return frame.args['error'] or frame:getParent().args['error'] or '?'
Anonymous user