Module:Gradient: Difference between revisions
From MuttWiki
				
				
				Jump to navigationJump to search
				
				
 Created page with "local p={}  function parse_colour(c) 	return { 		tonumber(string.sub(c,1,2),16), 		tonumber(string.sub(c,3,4),16), 		tonumber(string.sub(c,5,6),16) 	} end function fmt_colour(r,g,b) 	return string.format("%02x%02x%02x",math.floor(r),math.floor(g),math.floor(b)) end  function p.rgb(frame) 	local r,g,b = parse_colour(frame.args[1]) 	local r2,g2,b2 = parse_colour(frame.args[2]) 	local text = frame.args[3] 	local n = mw.ustring.len(text) 	local out = "" 	local dr,dg,db = (r2..."  | 
			
(No difference) 
 | 
Revision as of 09:11, 22 February 2025
Lua error at line 20: attempt to perform arithmetic on local 'r2' (a table value). It contains the following functions:
rgb
{{#invoke:Gradient|rgb|<from>|<to>|<text>}}
- from: A 6-digit hex code for the start colour. No starting 
#. - to: A 6-digit hex code for the end colour. No starting 
#. - text: The text to apply the gradient effect to. Plain text only.
 
Example: {{#invoke:Gradient|rgb|FF0000|0000FF|Hello world!}} → Lua error at line 20: attempt to perform arithmetic on local 'r2' (a table value).
multi
{{#invoke:Gradient|multi|<colours>|<text>}}
- colours: A comma-separated list of 6-digit hex codes. No starting 
#s. - text: The text to apply the gradient effect to. Plain text only.
 
Example: {{#invoke:Gradient|multi|FF0000,FFFF00,00FF00,00FFFF,0000FF,FF00FF|Hello world!}} → Script error: The function "multi" does not exist.
local p={}
function parse_colour(c)
	return {
		tonumber(string.sub(c,1,2),16),
		tonumber(string.sub(c,3,4),16),
		tonumber(string.sub(c,5,6),16)
	}
end
function fmt_colour(r,g,b)
	return string.format("%02x%02x%02x",math.floor(r),math.floor(g),math.floor(b))
end
function p.rgb(frame)
	local r,g,b = parse_colour(frame.args[1])
	local r2,g2,b2 = parse_colour(frame.args[2])
	local text = frame.args[3]
	local n = mw.ustring.len(text)
	local out = ""
	local dr,dg,db = (r2-r)/n, (g2-g)/n, (b2-b)/n
	for i=1,n do
		local ch = mw.ustring.codepoint(text,i,i)
		out = out.."<span style='color: #"..fmt_colour(r,g,b)..";'>"..mw.text.nowiki(ch).."</span>"
		r=r+dr
		g=g+dg
		b=b+db
	end
	return out
end
return p