Module:Color contrast: Difference between revisions
simplify, already lowercased
m>Frietjes (add support for rgb(x,y,z)) |
m>Frietjes (simplify, already lowercased) |
||
Line 76: | Line 76: | ||
-- convert from hsl | -- convert from hsl | ||
if mw.ustring.match(c,'^ | if mw.ustring.match(c,'^hsl%([%s]*[0-9][0-9]*[%s]*,[%s]*[0-9][0-9]*%%[%s]*,[%s]*[0-9][0-9]*%%[%s]*%)$') then | ||
local h, s, l = mw.ustring.match(c,'^ | local h, s, l = mw.ustring.match(c,'^hsl%([%s]*([0-9][0-9]*)[%s]*,[%s]*([0-9][0-9]*)%%[%s]*,[%s]*([0-9][0-9]*)%%[%s]*%)$') | ||
return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100) | return hsl2lum(tonumber(h), tonumber(s)/100, tonumber(l)/100) | ||
end | end | ||
-- convert from rgb | -- convert from rgb | ||
if mw.ustring.match(c,'^ | if mw.ustring.match(c,'^rgb%([%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,'^ | local R, G, B = mw.ustring.match(c,'^rgb%([%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)) | return rgbdec2lum(tonumber(R), tonumber(G), tonumber(B)) | ||
end | end |