Toggle menu
15
236
70
27.5K
Kenshi Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 04:15, 7 March 2025 by Prd (talk | contribs) (Created page with "local getArgs = require('Module:Arguments').getArgs local p = {} local function rgb(color) local _, _, R, G, B = color:find('(%w%w)(%w%w)(%w%w)') return tonumber(R, 16), tonumber(G, 16), tonumber(B, 16) end function p.main(frame) local args = getArgs(frame) local value = tonumber(args[1]) local minValue = tonumber(args[2]) local maxValue = tonumber(args[3]) if not (value and minValue and maxValue) then return require('Module:Error').error{'Parameters 1, 2,...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Implements {{Value color}}.



local getArgs = require('Module:Arguments').getArgs
local p = {}

local function rgb(color)
	local _, _, R, G, B = color:find('(%w%w)(%w%w)(%w%w)')
	return tonumber(R, 16), tonumber(G, 16), tonumber(B, 16)
end

function p.main(frame)
	local args = getArgs(frame)

	local value = tonumber(args[1])
	local minValue = tonumber(args[2])
	local maxValue = tonumber(args[3])
	
	if not (value and minValue and maxValue) then
		return require('Module:Error').error{'Parameters 1, 2, and 3 are required and must be numbers.'}
	end
	
	local minR, minG, minB = rgb(args[4] or 'FFFFFF')
	local maxR, maxG, maxB = rgb(args[5] or '000000')
	local percent = math.max(0, math.min(1, (value - minValue) / (maxValue - minValue)))
	
	local red = minR + ((maxR - minR) * percent)
	local green = minG + ((maxG - minG) * percent)
	local blue = minB + ((maxB - minB) * percent)
	
	local formatString = args['hex'] and '#%02x%02x%02x' or 'rgb(%.0f,%.0f,%.0f)'
	return string.format(formatString, red, green, blue)
end

return p