Home
Random
Recent changes
Special pages
Community portal
Preferences
About Stockhub
Disclaimers
Search
User menu
Talk
Contributions
Create account
Log in
Editing
Module:Sandbox/Drewmutt/SwatchGrid
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
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, level end local tileSizeW local tileSizeH local tileSpacingW local tileSpacingH function getSwatchTileString(r, g, b) local divstart = "<div style='margin-left:"..tileSpacingW..";margin-right:"..tileSpacingW..";display:inline-block;width:"..tileSizeW..";height:"..tileSizeH..";background-color:HSL(" local divend = "%)'> </div>" local a2, b2, c2 = rgbToHsl(r, g, b) return divstart .. (a2 * 360) .. "," .. (b2 * 100) .. "%," .. (c2 * 100) .. divend end function p.swatchgrid(frame) local a = frame.args local colors = {} colors[1] = { a[5], a[6], a[7] } colors[2] = { a[8], a[9], a[10] } colors[3] = { a[11], a[12], a[13] } colors[4] = { a[14], a[15], a[16] } colors[5] = { a[17], a[18], a[19] } tileSizeW = a[1] tileSizeH = a[2] tileSpacingW = a[3] tileSpacingH = a[4] local tiles = 5 local hdivide = "<div style='height:"..tileSpacingH.."'></div>" 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 result end return p
Summary:
Please note that all contributions to Stockhub may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Stockhub:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Sandbox/Drewmutt/SwatchGrid/doc
(
edit
)