Module:DropsLineTest: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local p = {}
-- Define a function to generate output numbers based on the input
local function generateOutput(input)
    local output = {}


-- Define a function to assign background color based on input numerical value
    -- Add the input number
local function assignBackgroundColor(value)
    table.insert(output, input)
    local color = ""
 
     -- Define your conditions and corresponding colors
     -- Calculate and add percentages
     if value == 1 then
     table.insert(output, input * 0.1) -- 10%
        color = "#afeeee" -- Light blue color
     table.insert(output, input * 0.2) -- 20%
     elseif value == 1/25 then
     table.insert(output, input * 0.3) -- 30%
        color = "#56e156" -- Light green color
     table.insert(output, input * 0.4) -- 40%
     elseif value == 1/99.99 then
     table.insert(output, input * 0.5) -- 50%
        color = "#ffed4c" -- Yellow color
 
     elseif value == 1/999.99 then
     return output
        color = "#ff863c" -- Orange color
     elseif value == 1/9999999 then
        color = "#ff6262" -- Red color
    else
        color = "#FFFFFF" -- Default color (white)
    end
     return color
end
end


-- Define a function to create a table row with colored cells
-- Test the script with an example input
function p.createColoredRow(frame)
local inputNumber = 100 -- Example input number
    local args = frame.args
local outputNumbers = generateOutput(inputNumber)
    local data = {}
for i, number in ipairs(outputNumbers) do
    for k, v in pairs(args) do
    print("Number " .. i .. ": " .. number)
        table.insert(data, v)
    end
    local row = ""
    for _, value in ipairs(data) do
        local color = assignBackgroundColor(tonumber(value))
        row = row .. "" .. color .. ";\" | " .. value .. "\n"
    end
    return row
end
end
return p

Revision as of 17:06, 5 May 2024

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

-- Define a function to generate output numbers based on the input
local function generateOutput(input)
    local output = {}

    -- Add the input number
    table.insert(output, input)

    -- Calculate and add percentages
    table.insert(output, input * 0.1) -- 10%
    table.insert(output, input * 0.2) -- 20%
    table.insert(output, input * 0.3) -- 30%
    table.insert(output, input * 0.4) -- 40%
    table.insert(output, input * 0.5) -- 50%

    return output
end

-- Test the script with an example input
local inputNumber = 100 -- Example input number
local outputNumbers = generateOutput(inputNumber)
for i, number in ipairs(outputNumbers) do
    print("Number " .. i .. ": " .. number)
end