Jump to content

Module:Splash: Difference between revisions

1,357 bytes added ,  13 March 2023
m
Now checks the width for each character. I don't really know if this was needed but it helps make it more accurate.
imported>Ttv pedro270707
m (Splash can now be chosen if desired. The argument is "splash".)
imported>Ttv pedro270707
m (Now checks the width for each character. I don't really know if this was needed but it helps make it more accurate.)
Line 1: Line 1:
local p = {}
local p = {}
local splashes = require("Module:Splash/splashes")
local splashes = require("Module:Splash/splashes")
local charWidths = {
    ['!'] = 2, ['.'] = 2, [','] = 2, [':'] = 2, ['\''] = 2, ['i'] = 2, -- width 1 characters
    ['l'] = 3, -- width 2 characters
    ['I'] = 4, ['t'] = 4, -- width 3 characters
    ['k'] = 5, ['<'] = 5, ['>'] = 5, ['f'] = 5, -- width 4 characters
    ['A'] = 6, ['B'] = 6, ['C'] = 6, ['D'] = 6, ['E'] = 6, ['F'] = 6, ['G'] = 6, ['H'] = 6, ['J'] = 6, ['K'] = 6, ['L'] = 6, ['M'] = 6, ['N'] = 6, ['O'] = 6, ['P'] = 6, ['Q'] = 6, ['R'] = 6, ['S'] = 6, ['T'] = 6, ['U'] = 6, ['V'] = 6, ['W'] = 6, ['X'] = 6, ['Y'] = 6, ['Z'] = 6,
    ['a'] = 6, ['b'] = 6, ['c'] = 6, ['d'] = 6, ['e'] = 6, ['g'] = 6, ['h'] = 6, ['j'] = 6, ['m'] = 6, ['n'] = 6, ['o'] = 6, ['p'] = 6, ['q'] = 6, ['r'] = 6, ['s'] = 6, ['u'] = 6, ['v'] = 6, ['w'] = 6, ['x'] = 6, ['y'] = 6, ['z'] = 6,
    ['0'] = 6, ['1'] = 6, ['2'] = 6, ['3'] = 6, ['4'] = 6, ['5'] = 6, ['6'] = 6, ['7'] = 6, ['8'] = 6, ['9'] = 6, ['='] = 6, ['-'] = 6, ['^'] = 6
}


function p.generateSplash( f )
function p.generateSplash( f )
Line 28: Line 38:
randomSplash = splashes.splashes[math.random(#splashes.splashes)]
randomSplash = splashes.splashes[math.random(#splashes.splashes)]
end
end
local splashWidth = 0
for i = 1, #randomSplash do
        local char = randomSplash:sub(i, i)
       
        -- Look up the pixel width of the character in the table
        local charWidth = charWidths[char]
        if not charWidth then
            charWidth = 5 -- Default width
        end
       
        -- Add the pixel width of the character to the total width
        splashWidth = splashWidth + charWidth
    end


local div = mw.html.create('div')
local div = mw.html.create('div')
Line 33: Line 57:
     :attr('id', 'splash-text')
     :attr('id', 'splash-text')
     :wikitext(randomSplash)
     :wikitext(randomSplash)
     :css('font-size', tostring(2880 / (#randomSplash*6 + 32)) .. 'px')
     :css('font-size', tostring(2880 / (splashWidth + 32)) .. 'px')
      
      
     return div
     return div