Module:GTest

From Wavu Wiki, the 🌊 wavy Tekken wiki
Revision as of 17:50, 9 November 2023 by Kalki (talk | contribs) (Created page with "-- Take a number and calculate how many steps in the gradient it is. -- Output is a class name defined in MediaWiki:Common.css. local yesno = require('Module:Yesno') local p...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

-- Take a number and calculate how many steps in the gradient it is.
-- Output is a class name defined in MediaWiki:Common.css.

local yesno = require('Module:Yesno')
local p = {}

local steps = 15
local palette = 'diverging-red-blue'

p.main = function(frame)
	local val = tonumber(frame.args[1])
	if val == nil then return '' end
	local right = tonumber(frame.args['right']) or 100
	local left = tonumber(frame.args['left']) or right * -1
	local invert = yesno(frame.args['invert'], false)
	return p._main(val, left, right, invert)
end

p._main = function(val, left, right, invert)
	invert = invert or false
	local step = math.max(0, math.min(steps - 1,
		math.floor((val - left) * (steps - 1) / (right - left))
	))
	if invert then step = steps - 1 - step end
	return 'gradient_' .. palette .. '_' .. step
end

return p