Anonymous user
Module:Color contrast: Difference between revisions
add support for rgb(x,y,z)
(combine) |
(add support for rgb(x,y,z)) |
||
Line 19:
local function rgbdec2lum( R, G, B )
if ( 0 <= R and R < 256 and 0 <= G and G < 256 and 0 <= B and B < 256 ) then
else
end
end
local function hsl2lum( h, s, l )
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then
local c = (1 - math.abs(2*l - 1))*s
Line 49 ⟶ 52:
b = b + x
end
else
return ''
end
▲ return lum
end
Line 72 ⟶ 76:
-- convert from hsl
if mw.ustring.match(c,'^
local h, s, l = mw.ustring.match(c,'^
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100)
end
-- convert from rgb
if mw.ustring.match(c,'^[Rr][Gg][Bb]%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*[%s]*%)$') then
local R, G, B = mw.ustring.match(c,'^[Rr][Gg][Bb]%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)[%s]*%)$')
return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B))
end
|