66 476
contributi
(Copiato da memoryg2) |
(TItles in example output) |
||
(10 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 20: | Riga 20: | ||
local Intro = 'Questo esempio è automaticamente generato tramite script LUA a partire dal codice di esempio presente in <code>[[' .. SubPageTitle.prefixedText .. ']]</code>' | local Intro = 'Questo esempio è automaticamente generato tramite script LUA a partire dal codice di esempio presente in <code>[[' .. SubPageTitle.prefixedText .. ']]</code>' | ||
local CodeString = 'Il codice' | local CodeString = '=== Il codice ===' | ||
local ReturnString = 'restituisce' | local ReturnString = '=== restituisce ===' | ||
Content = SubPageTitle:getContent() | Content = SubPageTitle:getContent() | ||
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(frame) | |||
local hex = string.sub(frame.args[1], 2) | |||
local R, G, B | |||
local L | |||
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 | |||
L = (R * 0.299 + G * 0.587 + B * 0.114) --/ 256 | |||
if L < 0.5 then | |||
return "white" | |||
else | |||
return "black" | |||
end | |||
end | end | ||
return p | return p |