Module:G: Difference between revisions

From Wavu Wiki, the 🌊 wavy Tekken wiki
(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 p = {} local steps = 15 local palette =...")
 
No edit summary
Line 8: Line 8:


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

Revision as of 00:53, 11 August 2021

Documentation for this module may be created at Module:G/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 p = {}

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

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
	return p._main(val, left, right)
end

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

p.err = function (msg)
	
end

return p