Module:Color contrast: Difference between revisions

(typo)
Line 2:
-- This module implements
-- {{Color contrast ratio}}
-- {{Greater contrast ratio}}
-- {{ColorToLum}}
-- {{RGBColorToLum}}
Line 120 ⟶ 121:
-- failure, return blank
return ''
end
 
function p._greatercontrast(args)
local bias = tonumber(args['bias'] or '0') or 0
local v1 = color2lum(args[1] or '')
local c2 = args[2] or '#FFFFFF'
local v2 = color2lum(c2)
local c3 = args[3] or '#000000'
local v3 = color2lum(c3)
local ratio1 = 0;
local ratio2 = 0;
if (type(v1) == 'number' and type(v2) == 'number') then
ratio1 = (v2 + 0.05)/(v1 + 0.05)
ratio1 = (ratio1 < 1) and 1/ratio1 or ratio1
end
if (type(v1) == 'number' and type(v3) == 'number') then
ratio1 = (v3 + 0.05)/(v1 + 0.05)
ratio1 = (ratio1 < 1) and 1/ratio1 or ratio1
end
return (ratio1 + bias > ratio2) and c2 or c3
end
 
Line 140 ⟶ 161:
return p._ratio(args)
end
 
function p.greatercontrast(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
return p._greatercontrast(args)
end
 
return p
Anonymous user