Module:ColorParse: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
(bordered works now) |
||
Line 118: | Line 118: | ||
local finaltbl = {} | local finaltbl = {} | ||
local interval = 1 | local interval = 1 | ||
local bordered = false | |||
local overflowbehavior = function(f) return 'y' end | |||
if type == 'alternation' then | if type == 'alternation' then | ||
interval = math.floor(#strtbl/#colorlist) --sets interval that color code switches. | interval = math.floor(#strtbl/#colorlist) --sets interval that color code switches. | ||
Line 123: | Line 125: | ||
elseif type == 'sequence' then | elseif type == 'sequence' then | ||
overflowbehavior = function(f) | overflowbehavior = function(f) | ||
local e = f%#colorlist | local e = f%#colorlist | ||
if e == 0 then e = #colorlist end | if e == 0 then e = #colorlist end | ||
return colorlist[e] | return colorlist[e] | ||
end | end | ||
else | elseif type == 'bordered' then | ||
overflowbehavior = function(f) return 'y' end | bordered = true | ||
overflowbehavior = function(f) | |||
if f + #strtbl == 3 then return colorlist[2] else return colorlist[1] end | |||
end | |||
elseif type == 'chaotic' then | |||
overflowbehavior = function(f) return 'y' end -- placeholder | |||
end | end | ||
local ci = 1 | local ci = 1 | ||
if bordered == true then | |||
ci = #colorlist | |||
end | |||
for i=1, #strtbl do | for i=1, #strtbl do | ||
if ci > #colorlist then | if ci > #colorlist or ci <= 0 then | ||
hexcolor = overflowbehavior(ci) | hexcolor = overflowbehavior(ci) | ||
else | else | ||
Line 139: | Line 149: | ||
finaltbl[i] = "<span style=\"color: " .. luatable.parse(hexcolor) .. ";\">" .. strtbl[i].. "</span>" | finaltbl[i] = "<span style=\"color: " .. luatable.parse(hexcolor) .. ";\">" .. strtbl[i].. "</span>" | ||
if i%interval == 0 then | if i%interval == 0 then | ||
ci = ci + 1 | if bordered == true then | ||
ci = ci - 1 | |||
else | |||
ci = ci + 1 | |||
end | |||
end | end | ||
end | end | ||
Line 176: | Line 190: | ||
function p.test() | function p.test() | ||
return applytemplate('structural', 'structural') | --return applytemplate('structural', 'structural') | ||
--return p.shader('Stopsvalinn', 'R-r-K-y-Y', 'sequence') | --return p.shader('Stopsvalinn', 'R-r-K-y-Y', 'sequence') | ||
return applytemplate('horned', 'horned') | |||
end | end | ||
return p | return p |