Module:DropsClue: Difference between revisions
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 |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
-- Define a function to generate output | -- 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 = {} | ||
-- | -- Define color thresholds and corresponding colors | ||
local thresholds = {100, 200, 300, 400, 500} -- Thresholds | |||
local colors = {"#ff9999", "#7aa7ff", "#d699ff", "#fff59e", "#b3f1ff"} -- Corresponding colors | |||
-- | -- Find the appropriate color based on the input number | ||
local | local colorIndex = 1 | ||
for i, threshold in ipairs(thresholds) do | |||
if inputNumber >= threshold then | |||
for i, | colorIndex = i | ||
else | |||
break | |||
end | |||
end | end | ||
-- Add the input number with the appropriate background color | |||
local color = colors[colorIndex] | |||
table.insert(output, "| style=\"background-color: " .. color .. ";\" | " .. inputNumber) | |||
return table.concat(output, '\n') | return table.concat(output, '\n') | ||
end | end | ||
return p | return p |
Revision as of 18:09, 7 May 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 = {100, 200, 300, 400, 500} -- Thresholds
local colors = {"#ff9999", "#7aa7ff", "#d699ff", "#fff59e", "#b3f1ff"} -- 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 .. ";\" | " .. inputNumber)
return table.concat(output, '\n')
end
return p