67 741
contributi
(Copiato da memoryg2) |
(First TextColor iteration) |
||
Riga 94: | Riga 94: | ||
function p.NoWiki(frame) | function p.NoWiki(frame) | ||
return mw.text.nowiki(frame.args[1]) | return mw.text.nowiki(frame.args[1]) | ||
end | |||
--- Returns the color to use in CSS for the text depending on the luminance | |||
-- of the background | |||
-- @param BackColor The hex code of the background color | |||
-- @return name of the color | |||
function p.TextColor(BackColor) | |||
local hex = BackColor:gsub("#","") | |||
local R, G, B | |||
if hex:len() == 3 then | |||
--return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255 | |||
R = tonumber("0x"..hex:sub(1,1))*17/255 | |||
G = tonumber("0x"..hex:sub(2,2))*17/255 | |||
B = tonumber("0x"..hex:sub(3,3))*17/255 | |||
else | |||
R = tonumber("0x"..hex:sub(1,2))/255 | |||
G = tonumber("0x"..hex:sub(3,4))/255 | |||
B = tonumber("0x"..hex:sub(5,6))/255 | |||
end | |||
return (R * 0.299 + G * 0.587 + B * 0.114) / 256 | |||
end | end | ||
return p | return p |