<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3AHexShade</id>
	<title>Module:HexShade - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.stiles.casa/index.php?action=history&amp;feed=atom&amp;title=Module%3AHexShade"/>
	<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:HexShade&amp;action=history"/>
	<updated>2026-04-07T09:12:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.2</generator>
	<entry>
		<id>https://wiki.stiles.casa/index.php?title=Module:HexShade&amp;diff=8045&amp;oldid=prev</id>
		<title>imported&gt;Julio974fr: Fix, saturation was not correctly interpreted for some colors</title>
		<link rel="alternate" type="text/html" href="https://wiki.stiles.casa/index.php?title=Module:HexShade&amp;diff=8045&amp;oldid=prev"/>
		<updated>2022-01-08T22:30:29Z</updated>

		<summary type="html">&lt;p&gt;Fix, saturation was not correctly interpreted for some colors&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- This module implements {{HexShade}}&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
local function rgbdec2hex(r, g, b, d)&lt;br /&gt;
	if (r &amp;gt;= 0 and g &amp;gt;= 0 and b &amp;gt;= 0 ) then&lt;br /&gt;
		local baseconvert = require(&amp;#039;Module:BaseConvert&amp;#039;)&lt;br /&gt;
		local s1 = baseconvert.convert({n = math.floor(r+0.5), base = 16})&lt;br /&gt;
		local s2 = baseconvert.convert({n = math.floor(g+0.5), base = 16})&lt;br /&gt;
		local s3 = baseconvert.convert({n = math.floor(b+0.5), base = 16})&lt;br /&gt;
		s1 = mw.ustring.gsub(s1, &amp;#039;^([0-9A-Fa-f])$&amp;#039;, &amp;#039;0%1&amp;#039;)&lt;br /&gt;
		s2 = mw.ustring.gsub(s2, &amp;#039;^([0-9A-Fa-f])$&amp;#039;, &amp;#039;0%1&amp;#039;)&lt;br /&gt;
		s3 = mw.ustring.gsub(s3, &amp;#039;^([0-9A-Fa-f])$&amp;#039;, &amp;#039;0%1&amp;#039;)&lt;br /&gt;
		return (s1 .. s2 .. s3):upper()&lt;br /&gt;
	end&lt;br /&gt;
	return d&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function rgbdec2hsl(r, g, b)&lt;br /&gt;
	local H, S, L&lt;br /&gt;
	-- hue&lt;br /&gt;
	if ((r == g) and (g == b)) then&lt;br /&gt;
		H = 0&lt;br /&gt;
	elseif ((g &amp;gt;= r) and (g &amp;gt;= b)) then&lt;br /&gt;
		if (r &amp;gt; b) then&lt;br /&gt;
			H = 120 - 60 * (r - b) / (g - b)&lt;br /&gt;
		else &lt;br /&gt;
			H = 120 + 60 * (b - r) / (g - r)&lt;br /&gt;
		end&lt;br /&gt;
	elseif ((b &amp;gt;= r) and (b &amp;gt;= g)) then&lt;br /&gt;
		if (g &amp;gt; r) then&lt;br /&gt;
			H = 240 - 60 * (g - r) / (b - r)&lt;br /&gt;
		else &lt;br /&gt;
			H = 240 + 60 * (r - g) / (b - g)&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if (b &amp;gt; g) then &lt;br /&gt;
			H = 360 - 60 * (b - g) / (r - g)&lt;br /&gt;
		else &lt;br /&gt;
			H = 60 * (g - b) / (r - b)&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	-- saturation&lt;br /&gt;
	if ((r == g) and (g == b)) then&lt;br /&gt;
		S = 0&lt;br /&gt;
	elseif ((g &amp;gt;= r) and (g &amp;gt;= b)) then&lt;br /&gt;
		if (r &amp;gt; b) then&lt;br /&gt;
			if ((g + b) &amp;gt; 255) then&lt;br /&gt;
				S = (g - b) / (510 - g - b)&lt;br /&gt;
			else&lt;br /&gt;
				S = (g - b) / (g + b)&lt;br /&gt;
			end&lt;br /&gt;
		else &lt;br /&gt;
			if ((g + r) &amp;gt; 255) then&lt;br /&gt;
				S = (g - r) / (510 - g - r)&lt;br /&gt;
			else&lt;br /&gt;
				S = (g - r) / (g + r)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	elseif ((r &amp;gt;= b) and (r &amp;gt;= g)) then&lt;br /&gt;
		if (b &amp;gt; g) then&lt;br /&gt;
			if ((r + g) &amp;gt; 255) then&lt;br /&gt;
				S = (r - g) / (510 - r - g)&lt;br /&gt;
			else&lt;br /&gt;
				S = (r - g) / (r + g)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			if ((r + b) &amp;gt; 255) then&lt;br /&gt;
				S = (r - b) / (510 - r - b)&lt;br /&gt;
			else &lt;br /&gt;
				S = (r - b) / (r + b)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	else&lt;br /&gt;
		if (g &amp;gt; r) then&lt;br /&gt;
			if ((b + r) &amp;gt; 255) then&lt;br /&gt;
				S = (b - r) / (510 - b - r)&lt;br /&gt;
			else &lt;br /&gt;
				S = (b - r) / (b + r)&lt;br /&gt;
			end&lt;br /&gt;
		else&lt;br /&gt;
			if ((b + g) &amp;gt; 255) then &lt;br /&gt;
				S = (b - g) / (510 - b - g)&lt;br /&gt;
			else &lt;br /&gt;
				S = (b - g) / (b + g)&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- luminosity&lt;br /&gt;
	L = (math.max(r, math.max(g, b)) + math.min(r, math.min(g, b))) / (255 * 2)&lt;br /&gt;
	&lt;br /&gt;
	return H, S, L&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function hsl2rgbdec(h, s, l)&lt;br /&gt;
	-- This function came from [[Module:Color contrast]]&lt;br /&gt;
	if ( 0 &amp;lt;= h and h &amp;lt; 360 and 0 &amp;lt;= s and s &amp;lt;= 1 and 0 &amp;lt;= l and l &amp;lt;= 1 ) then&lt;br /&gt;
		local c = (1 - math.abs(2*l - 1))*s&lt;br /&gt;
		local x = c*(1 - math.abs( math.fmod(h/60, 2) - 1) )&lt;br /&gt;
		local m = l - c/2&lt;br /&gt;
&lt;br /&gt;
		local r, g, b = m, m, m&lt;br /&gt;
		if( 0 &amp;lt;= h and h &amp;lt; 60 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			g = g + x&lt;br /&gt;
		elseif( 60 &amp;lt;= h and h &amp;lt; 120 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			g = g + c&lt;br /&gt;
		elseif( 120 &amp;lt;= h and h &amp;lt; 180 ) then&lt;br /&gt;
			g = g + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		elseif( 180 &amp;lt;= h and h &amp;lt; 240 ) then&lt;br /&gt;
			g = g + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 240 &amp;lt;= h and h &amp;lt; 300 ) then&lt;br /&gt;
			r = r + x&lt;br /&gt;
			b = b + c&lt;br /&gt;
		elseif( 300 &amp;lt;= h and h &amp;lt; 360 ) then&lt;br /&gt;
			r = r + c&lt;br /&gt;
			b = b + x&lt;br /&gt;
		end&lt;br /&gt;
	&lt;br /&gt;
		return 255*r, 255*g, 255*b&lt;br /&gt;
	end&lt;br /&gt;
	return -1, -1, -1&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame)&lt;br /&gt;
	&lt;br /&gt;
	-- Remove nowiki and leading hash signs&lt;br /&gt;
	local c = mw.text.unstrip(args[1] or &amp;#039;#f0e68c&amp;#039;)&lt;br /&gt;
	c = mw.ustring.match(c, &amp;#039;^[%s]*(.-)[%s]*$&amp;#039;)&lt;br /&gt;
	c = mw.ustring.gsub(c, &amp;#039;^[%s#]*&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	c = mw.ustring.gsub(c, &amp;#039;^&amp;amp;#35;[%s]*&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	-- Lowercase&lt;br /&gt;
	c = c:lower()&lt;br /&gt;
	mw.log(c)&lt;br /&gt;
	-- Expand short 3 hex for to 6 hex form&lt;br /&gt;
	c = mw.ustring.gsub(c, &amp;#039;^([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])$&amp;#039;, &amp;#039;%1%1%2%2%3%3&amp;#039;)&lt;br /&gt;
	mw.log(c)&lt;br /&gt;
	&lt;br /&gt;
	-- Get new value for luminosity&lt;br /&gt;
	local Lnew = tonumber(args[2] or &amp;#039;-1&amp;#039;) or 0.6&lt;br /&gt;
	&lt;br /&gt;
	-- Default return&lt;br /&gt;
	local res = c&lt;br /&gt;
	&lt;br /&gt;
	-- Adjust shading&lt;br /&gt;
	local cs = mw.text.split(c or &amp;#039;&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
	if( #cs == 6 ) then&lt;br /&gt;
		-- Convert to RGBdec&lt;br /&gt;
		local R = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[1]) + tonumber(&amp;#039;0x&amp;#039; .. cs[2])&lt;br /&gt;
		local G = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[3]) + tonumber(&amp;#039;0x&amp;#039; .. cs[4])&lt;br /&gt;
		local B = 16*tonumber(&amp;#039;0x&amp;#039; .. cs[5]) + tonumber(&amp;#039;0x&amp;#039; .. cs[6])&lt;br /&gt;
		mw.log(R, G, B)&lt;br /&gt;
&lt;br /&gt;
		-- Convert RGBdec to HSL&lt;br /&gt;
		local H, S, L = rgbdec2hsl(R, G, B)&lt;br /&gt;
		mw.log(H, S, L)&lt;br /&gt;
		&lt;br /&gt;
		-- Convert back to RGBdec&lt;br /&gt;
		local R, G, B = hsl2rgbdec(H, S, Lnew)&lt;br /&gt;
		&lt;br /&gt;
		-- Convert back to RGBhex&lt;br /&gt;
		res = rgbdec2hex(R, G, B, c)&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	res = res:upper()&lt;br /&gt;
	&lt;br /&gt;
	if args[3] == &amp;#039;#&amp;#039; and mw.ustring.match(res, &amp;#039;^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$&amp;#039;) then&lt;br /&gt;
		return &amp;#039;#&amp;#039; .. res&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return res&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>imported&gt;Julio974fr</name></author>
	</entry>
</feed>