Module:Color contrast: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
simplify, already lowercased
(add support for rgb(x,y,z))
(simplify, already lowercased)
Line 76:
 
-- convert from hsl
if mw.ustring.match(c,'^[Hh][Ss][Ll]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,'^[Hh][Ss][Ll]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)
end
 
-- convert from rgb
if mw.ustring.match(c,'^[Rr][Gg][Bb]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,'^[Rr][Gg][Bb]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))
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu