Module:DropsClue: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
(Created page with "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", "...")
 
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}


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


     -- Add the input number
     -- Define color thresholds and corresponding colors
     table.insert(output, "\" | 1/" .. inputNumber)
     local thresholds = {1, 2, 26, 100, 1000} -- Thresholds
    local colors = {"#0b5884", "#3c780a", "#a48900", "#b55e0c", "#9f261e"} -- Corresponding colors


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


return p
return p

Latest revision as of 14:37, 21 June 2024

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

local p = {}

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

    -- Define color thresholds and corresponding colors
    local thresholds = {1, 2, 26, 100, 1000} -- Thresholds
    local colors = {"#0b5884", "#3c780a", "#a48900", "#b55e0c", "#9f261e"} -- Corresponding colors

    -- Find the appropriate color based on the input number
    local colorIndex = 1
    for i, threshold in ipairs(thresholds) do
        if inputNumber >= threshold then
            colorIndex = i
        else
            break
        end
    end

    -- Add the input number with the appropriate background color
    local color = colors[colorIndex]
    table.insert(output, " style=\"background-color: " .. color .. ";\" | 1/" ..  inputNumber)

    return table.concat(output, '\n')
end

return p