Module:ColorParse: Difference between revisions

Jump to navigation Jump to search
12 bytes added ,  22:48, 24 May 2020
localize vars
mNo edit summary
(localize vars)
Line 108: Line 108:
function p.shader(text, colors, type)
function p.shader(text, colors, type)
     -- split the colors into a list  
     -- split the colors into a list  
     colorlist = textutil.split(colors, '-')
     local colorlist = textutil.split(colors, '-')
     -- check shader type:
     -- check shader type:
     -- default    | if pattern is shorter than text, text will remain uncolored (y)
     -- default    | if pattern is shorter than text, text will remain uncolored (y)
     -- sequence    | pattern will repeat until text is over
     -- sequence    | pattern will repeat until text is over
     -- alternation | pattern will stretch to fit word length (?)
     -- alternation | pattern will stretch to fit word length (?)
     type = type or 'default'
     local type = type or 'default'
     strtbl = strtotbl(text)
     local strtbl = strtotbl(text)
     finaltbl = {}
     local finaltbl = {}
     interval = 1
     local interval = 1
     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 122: Line 122:
     elseif type == 'sequence' then
     elseif type == 'sequence' then
         overflowbehavior = function(f)  
         overflowbehavior = function(f)  
         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]  
Line 129: Line 129:
         overflowbehavior = function(f) return 'y' end
         overflowbehavior = function(f) return 'y' end
     end
     end
     ci = 1
     local ci = 1
     for i=1, #strtbl do
     for i=1, #strtbl do
       if ci > #colorlist then
       if ci > #colorlist then
Line 146: Line 146:
function p.shadermain(frame)
function p.shadermain(frame)
     local args = process_args.merge(true)
     local args = process_args.merge(true)
     if (args['unbolded'] ~= nil) and (args['unbolded'] == 'true') then
     if (args['unbolded'] == 'true') then
       return p.shader(args['text'], args['colors'], args['type'])
       return p.shader(args['text'], args['colors'], args['type'])
     else
     else

Navigation menu