Module:Color contrast: Difference between revisions
Content added Content deleted
No edit summary |
(refactor) |
||
Line 16: | Line 16: | ||
end |
end |
||
return v |
return v |
||
end |
|||
local function rgbdec2lum( R, G, B ) |
|||
⚫ | |||
end |
end |
||
Line 25: | Line 29: | ||
local m = l - c/2 |
local m = l - c/2 |
||
local |
local r, g, b = m, m, m |
||
if( 0 <= h and h < 60 ) then |
if( 0 <= h and h < 60 ) then |
||
r = r + c |
|||
g = g + x |
|||
elseif( 60 <= h and h < 120 ) then |
elseif( 60 <= h and h < 120 ) then |
||
r = r + x |
|||
g = g + c |
|||
elseif( 120 <= h and h < 180 ) then |
elseif( 120 <= h and h < 180 ) then |
||
g = g + c |
|||
b = b + x |
|||
elseif( 180 <= h and h < 240 ) then |
elseif( 180 <= h and h < 240 ) then |
||
g = g + x |
|||
b = b + c |
|||
elseif( 240 <= h and h < 300 ) then |
elseif( 240 <= h and h < 300 ) then |
||
r = r + x |
|||
b = b + c |
|||
elseif( 300 <= h and h < 360 ) then |
elseif( 300 <= h and h < 360 ) then |
||
r = r + c |
|||
b = b + x |
|||
end |
end |
||
lum = rgbdec2lum(255*r, 255*g, 255*b) |
|||
⚫ | |||
end |
end |
||
return lum |
return lum |
||
Line 81: | Line 85: | ||
local cs = mw.text.split(c or '', '') |
local cs = mw.text.split(c or '', '') |
||
if( #cs == 6 ) then |
if( #cs == 6 ) then |
||
local R = |
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2]) |
||
local G = |
local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4]) |
||
local B = |
local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6]) |
||
return rgbdec2lum(R, G, B) |
|||
L = 0.2126 * R + 0.7152 * G + 0.0722 * B |
|||
return L |
|||
elseif ( #cs == 3 ) then |
elseif ( #cs == 3 ) then |
||
local R = |
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[1]) |
||
local G = |
local G = 16*tonumber('0x' .. cs[2]) + tonumber('0x' .. cs[2]) |
||
local B = |
local B = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[3]) |
||
return rgbdec2lum(R, G, B) |
|||
L = 0.2126 * R + 0.7152 * G + 0.0722 * B |
|||
return L |
|||
end |
end |
||