模組:沙盒/Kurgenera/sandbox

来自Local Chinese Wikipedia
跳转到导航 跳转到搜索

此模块的文档可以在Module:沙盒/Kurgenera/sandbox/doc创建

local p = {}

function p.test(frame)
    local input = frame.args[1] or "Logic Beauty"
    local container = mw.html.create('div')
    
    container:css({
        ['position'] = 'relative',
        ['width'] = '100%',
        ['height'] = '200px',
        ['background'] = 'linear-gradient(to bottom, #ffffff 0%, #e0f7fa 100%)',
        ['border-radius'] = '25px',
        ['border'] = '2px solid #afeeee',
        ['overflow'] = 'hidden',
        ['display'] = 'flex',
        ['align-items'] = 'center',
        ['justify-content'] = 'center'
    })

    -- 将文字拆解为字符,每个字符都变成一个独立漂浮的“逻辑气泡”
    for i = 1, mw.ustring.len(input) do
        local char = mw.ustring.sub(input, i, i)
        local seed = mw.ustring.byte(char) + i -- 用字符本身作为算法种子
        math.randomseed(seed)
        
        local bubble = container:tag('span')
        bubble:css({
            ['display'] = 'inline-block',
            ['font-size'] = (20 + math.random(10, 30)) .. 'px',
            ['color'] = string.format('hsla(%d, 70%%, 50%%, 0.8)', math.random(180, 220)),
            ['transform'] = 'rotate(' .. math.random(-30, 30) .. 'deg) translate(' .. math.random(-10, 10) .. 'px)',
            ['text-shadow'] = '2px 2px 8px rgba(0,191,255,0.3)',
            ['font-weight'] = 'bold',
            ['margin'] = '0 5px',
            ['filter'] = 'blur(' .. (math.random(0, 20) / 10) .. 'px)', -- 模拟景深
            ['transition'] = 'all 0.5s ease' -- 配合 hover 产生微妙的交互
        })
        :wikitext(char)
    end

    return tostring(container)
end

return p