Module:Sandbox/Drewmutt/SwatchGrid explained

local p =

function rgbToHsl(r, g, b) r, g, b = r / 255, g / 255, b / 255

local max, min = math.max(r, g, b), math.min(r, g, b) local hue, sat, level

level = (max + min) / 2

if max

min then hue, sat = 0, 0 -- achromatic else local d = max - min if level > 0.5 then sat = d / (2 - max - min) else sat = d / (max + min) end if max

r then hue = (g - b) / d if g < b then hue = hue + 6 end elseif max

g then hue = (b - r) / d + 2 elseif max

b then hue = (r - g) / d + 4 end hue = hue / 6 end

return hue, sat, levelend

local tileSizeWlocal tileSizeHlocal tileSpacingWlocal tileSpacingH function getSwatchTileString(r, g, b) local divstart = "

 

" local a2, b2, c2 = rgbToHsl(r, g, b) return divstart .. (a2 * 360) .. "," .. (b2 * 100) .. "%," .. (c2 * 100) .. divendend

function p.swatchgrid(frame) local a = frame.args local colors = colors[1] = colors[2] = colors[3] = colors[4] = colors[5] =

tileSizeW = a[1] tileSizeH = a[2] tileSpacingW = a[3] tileSpacingH = a[4] local tiles = 5 local hdivide = "

" local result = ""

for i = 1, tiles, 1 do local color = colors[i] local h = color[1] local s = color[2] local v = color[3] s = s / 2 result = result .. getSwatchTileString(h, s, v) end result = result .. hdivide

for i = 1, tiles, 1 do local color = colors[i] local h = color[1] local s = color[2] local v = color[3] result = result .. getSwatchTileString(h, s, v) end result = result .. hdivide

for i = 1, tiles, 1 do local color = colors[i] local h = color[1] local s = color[2] local v = color[3] v = v / 2 result = result .. getSwatchTileString(h, s, v) end result = result .. hdivide

for i = 1, tiles, 1 do local color = colors[i] local h = color[1] local s = color[2] local v = color[3] h = (h + 20) % 360 result = result .. getSwatchTileString(h, s, v) end result = result .. hdivide

for i = 1, tiles, 1 do local color = colors[i] local h = color[1] local s = color[2] local v = color[3] h = (h + 40) % 360 result = result .. getSwatchTileString(h, s, v) end result = result .. hdivide

return resultend

return p