Module:DropsLineTest: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
 
(10 intermediate revisions by the same user not shown)
Line 6: Line 6:
     local output = {}
     local output = {}


     -- Define color ranges
     -- Add the input number
     local colorRanges = {
     table.insert(output, "\" | 1/" .. inputNumber)
        {1, 25, "#00FF00"},    -- Green for 1-25
        {26, 100, "#FFFF00"},  -- Yellow for 26-100
        {101, 1000, "#FFA500"} -- Orange for 101-1000
    }


     -- Determine color based on input number for each part of the output
     -- Calculate percentages and choose color based on the percentage
     local color = "#FF0000" -- Default to red for numbers 1001+
    local percentages = {0.85, 0.75, 0.70, 0.65, 0.60} -- Percentages
     for _, range in ipairs(colorRanges) do
     local colors = {"#ff9999", "#7aa7ff", "#d699ff", "#fff59e", "#b3f1ff"} -- Corresponding colors
         local min, max, rangeColor = unpack(range)
   
         if inputNumber >= min and inputNumber <= max then
     for i, percent in ipairs(percentages) do
            color = rangeColor
         local value = math.floor(inputNumber * percent)
            break
         local color = colors[i]
         end
         table.insert(output, "| style=\"background-color: " .. color .. ";\" | 1/" .. value)
     end
     end
   
    -- Add output with chosen color
    table.insert(output, "| style=\"background-color: " .. color .. ";\" | 1/" .. inputNumber)
    table.insert(output, "| style=\"background-color: " .. color .. ";\" | 1/" .. (inputNumber * 0.85)) -- 10%
    table.insert(output, "| style=\"background-color: " .. color .. ";\" | 1/" .. (inputNumber * 0.75)) -- 20%
      
      
     return table.concat(output, '\n')
     return table.concat(output, '\n')

Latest revision as of 17:59, 7 May 2024

Documentation for this module may be created at Module:DropsLineTest/doc

local p = {}

-- Define a function to generate output numbers based on the input
function p.generateOutput(frame)
    local inputNumber = tonumber(frame.args[1]) or 0
    local output = {}

    -- Add the input number
    table.insert(output, "\" | 1/" .. inputNumber)

    -- Calculate percentages and choose color based on the percentage
    local percentages = {0.85, 0.75, 0.70, 0.65, 0.60} -- Percentages
    local colors = {"#ff9999", "#7aa7ff", "#d699ff", "#fff59e", "#b3f1ff"} -- Corresponding colors
    
    for i, percent in ipairs(percentages) do
        local value = math.floor(inputNumber * percent)
        local color = colors[i]
        table.insert(output, "| style=\"background-color: " .. color .. ";\" | 1/" .. value)
    end
    
    return table.concat(output, '\n')
end

return p