https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AHexShade%2Fsandbox
Module:HexShade/sandbox - Revision history
2025-06-04T05:26:17Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:HexShade/sandbox&diff=1150226737&oldid=prev
Lemondoge: Further simplifications / improvements
2023-04-17T00:19:06Z
<p>Further simplifications / improvements</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 00:19, 17 April 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 18:</td>
<td colspan="2" class="diff-lineno">Line 18:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function rgbdec2hsl(r, g, b)</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>local function rgbdec2hsl(r, g, b)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local H, S, L</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local H, S, L</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_0_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_1_1_rhs"></a><ins style="font-weight: bold; text-decoration: none;"> </ins>local <ins style="font-weight: bold; text-decoration: none;">max</ins> = math.<ins style="font-weight: bold; text-decoration: none;">max</ins>(<ins style="font-weight: bold; text-decoration: none;">r</ins>, <ins style="font-weight: bold; text-decoration: none;">g</ins>, b)</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> local min = math.min(r, g, b)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- hue</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- hue</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if ((r == g) and (g == b)) then</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if ((r == g) and (g == b)) then</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 43:</td>
<td colspan="2" class="diff-lineno">Line 46:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if ((r == g) and (g == b)) then</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> if ((r == g) and (g == b)) then</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> S = 0</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> S = 0</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_2_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_3_0_rhs"></a><ins style="font-weight: bold; text-decoration: none;"> elseif</ins> ((max + min) > 255) then</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_3_lhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_3_1_rhs"></a> S = (max - min) / (510 - max - min)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> else</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> <del style="font-weight: bold; text-decoration: none;">local max</del> = <del style="font-weight: bold; text-decoration: none;">math.</del>max(<del style="font-weight: bold; text-decoration: none;">g,</del> <del style="font-weight: bold; text-decoration: none;">r,</del> <del style="font-weight: bold; text-decoration: none;">b</del>)</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> <ins style="font-weight: bold; text-decoration: none;">S</ins> = <ins style="font-weight: bold; text-decoration: none;">(</ins>max<ins style="font-weight: bold; text-decoration: none;"> - min) / </ins>(<ins style="font-weight: bold; text-decoration: none;">max</ins> <ins style="font-weight: bold; text-decoration: none;">+</ins> <ins style="font-weight: bold; text-decoration: none;">min</ins>)</div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_1_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_0_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del>local <del style="font-weight: bold; text-decoration: none;">min</del> = math.<del style="font-weight: bold; text-decoration: none;">min</del>(<del style="font-weight: bold; text-decoration: none;">g</del>, <del style="font-weight: bold; text-decoration: none;">r</del>, b)</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_3_0_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_2_lhs"></a><del style="font-weight: bold; text-decoration: none;"> if</del> ((max + min) > 255) then</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_3_1_rhs">⚫</a></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><a name="movedpara_6_3_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> S = (max - min) / (510 - max - min)</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> else</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> S = (max - min) / (max + min)</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> end</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- luminosity</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> -- luminosity</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> L = (<del style="font-weight: bold; text-decoration: none;">math.</del>max<del style="font-weight: bold; text-decoration: none;">(r, math.max(g, b))</del> + <del style="font-weight: bold; text-decoration: none;">math.</del>min<del style="font-weight: bold; text-decoration: none;">(r, math.min(g, b))</del>) / (255 * 2)</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> L = (max + min) / (255 * 2)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> </div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return H, S, L</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> return H, S, L</div></td>
</tr>
</table>
Lemondoge
https://en.wikipedia.org/w/index.php?title=Module:HexShade/sandbox&diff=1150195727&oldid=prev
Lemondoge: Create sandbox version of Module:HexShade; major simplifications
2023-04-16T20:36:35Z
<p>Create sandbox version of <a href="/wiki/Module:HexShade" title="Module:HexShade">Module:HexShade</a>; major simplifications</p>
<p><b>New page</b></p><div>-- This module implements {{HexShade}}<br />
local p = {}<br />
<br />
local function rgbdec2hex(r, g, b, d)<br />
if (r >= 0 and g >= 0 and b >= 0 ) then<br />
local baseconvert = require('Module:BaseConvert')<br />
local s1 = baseconvert.convert({n = math.floor(r+0.5), base = 16})<br />
local s2 = baseconvert.convert({n = math.floor(g+0.5), base = 16})<br />
local s3 = baseconvert.convert({n = math.floor(b+0.5), base = 16})<br />
s1 = mw.ustring.gsub(s1, '^([0-9A-Fa-f])$', '0%1')<br />
s2 = mw.ustring.gsub(s2, '^([0-9A-Fa-f])$', '0%1')<br />
s3 = mw.ustring.gsub(s3, '^([0-9A-Fa-f])$', '0%1')<br />
return (s1 .. s2 .. s3):upper()<br />
end<br />
return d<br />
end<br />
<br />
local function rgbdec2hsl(r, g, b)<br />
local H, S, L<br />
-- hue<br />
if ((r == g) and (g == b)) then<br />
H = 0<br />
elseif ((g >= r) and (g >= b)) then<br />
if (r > b) then<br />
H = 120 - 60 * (r - b) / (g - b)<br />
else <br />
H = 120 + 60 * (b - r) / (g - r)<br />
end<br />
elseif ((b >= r) and (b >= g)) then<br />
if (g > r) then<br />
H = 240 - 60 * (g - r) / (b - r)<br />
else <br />
H = 240 + 60 * (r - g) / (b - g)<br />
end<br />
else<br />
if (b > g) then <br />
H = 360 - 60 * (b - g) / (r - g)<br />
else <br />
H = 60 * (g - b) / (r - b)<br />
end<br />
end<br />
-- saturation<br />
if ((r == g) and (g == b)) then<br />
S = 0<br />
else<br />
local max = math.max(g, r, b)<br />
local min = math.min(g, r, b)<br />
<br />
if ((max + min) > 255) then<br />
S = (max - min) / (510 - max - min)<br />
else<br />
S = (max - min) / (max + min)<br />
end<br />
end<br />
<br />
-- luminosity<br />
L = (math.max(r, math.max(g, b)) + math.min(r, math.min(g, b))) / (255 * 2)<br />
<br />
return H, S, L<br />
end<br />
<br />
local function hsl2rgbdec(h, s, l)<br />
-- This function came from [[Module:Color contrast]]<br />
if ( 0 <= h and h < 360 and 0 <= s and s <= 1 and 0 <= l and l <= 1 ) then<br />
local c = (1 - math.abs(2*l - 1))*s<br />
local x = c*(1 - math.abs( math.fmod(h/60, 2) - 1) )<br />
local m = l - c/2<br />
<br />
local r, g, b = m, m, m<br />
if( 0 <= h and h < 60 ) then<br />
r = r + c<br />
g = g + x<br />
elseif( 60 <= h and h < 120 ) then<br />
r = r + x<br />
g = g + c<br />
elseif( 120 <= h and h < 180 ) then<br />
g = g + c<br />
b = b + x<br />
elseif( 180 <= h and h < 240 ) then<br />
g = g + x<br />
b = b + c<br />
elseif( 240 <= h and h < 300 ) then<br />
r = r + x<br />
b = b + c<br />
elseif( 300 <= h and h < 360 ) then<br />
r = r + c<br />
b = b + x<br />
end<br />
<br />
return 255*r, 255*g, 255*b<br />
end<br />
return -1, -1, -1<br />
end<br />
<br />
function p.main(frame)<br />
local args = require('Module:Arguments').getArgs(frame)<br />
<br />
-- Remove nowiki and leading hash signs<br />
local c = mw.text.unstrip(args[1] or '#f0e68c')<br />
c = mw.ustring.match(c, '^[%s]*(.-)[%s]*$')<br />
c = mw.ustring.gsub(c, '^[%s#]*', '')<br />
c = mw.ustring.gsub(c, '^&#35;[%s]*', '')<br />
-- Lowercase<br />
c = c:lower()<br />
mw.log(c)<br />
-- Expand short 3 hex for to 6 hex form<br />
c = mw.ustring.gsub(c, '^([0-9A-Fa-f])([0-9A-Fa-f])([0-9A-Fa-f])$', '%1%1%2%2%3%3')<br />
mw.log(c)<br />
<br />
-- Get new value for luminosity<br />
local Lnew = tonumber(args[2] or '-1') or 0.6<br />
<br />
-- Default return<br />
local res = c<br />
<br />
-- Adjust shading<br />
local cs = mw.text.split(c or '', '')<br />
if( #cs == 6 ) then<br />
-- Convert to RGBdec<br />
local R = 16*tonumber('0x' .. cs[1]) + tonumber('0x' .. cs[2])<br />
local G = 16*tonumber('0x' .. cs[3]) + tonumber('0x' .. cs[4])<br />
local B = 16*tonumber('0x' .. cs[5]) + tonumber('0x' .. cs[6])<br />
mw.log(R, G, B)<br />
<br />
-- Convert RGBdec to HSL<br />
local H, S, L = rgbdec2hsl(R, G, B)<br />
mw.log(H, S, L)<br />
<br />
-- Convert back to RGBdec<br />
local R, G, B = hsl2rgbdec(H, S, Lnew)<br />
<br />
-- Convert back to RGBhex<br />
res = rgbdec2hex(R, G, B, c)<br />
end<br />
<br />
res = res:upper()<br />
<br />
if args[3] == '#' and mw.ustring.match(res, '^[0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f][0-9A-Fa-f]$') then<br />
return '#' .. res<br />
end<br />
<br />
return res<br />
end<br />
<br />
return p</div>
Lemondoge