Last active
September 20, 2015 01:30
-
-
Save inmatarian/89310fa617284c3e8439 to your computer and use it in GitHub Desktop.
Generates a Gimp palette based on HSL color space with a fixed saturation level
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local floor = math.floor | |
function round(x) return math.floor(x+0.5) end | |
do | |
local function hue2rgb(p, q, t) | |
if t < 0 then t = t + 1 end | |
if t > 1 then t = t - 1 end | |
if t < 1/6 then return p + (q - p) * 6 * t end | |
if t < 1/2 then return q end | |
if t < 2/3 then return p + (q - p) * (2/3 - t) * 6 end | |
return p | |
end | |
--- HSL COLOR SPACE | |
-- @param h Range 0 to 360 | |
-- @param s Range 0 to 1 | |
-- @param l Range 0 to 1 | |
-- @returns r, g, b | |
function hsl2rgb(h, s, l) | |
h = (h % 360.0) / 360.0 | |
if s == 0 then | |
return round(l*255) | |
else | |
local q | |
if l < 0.5 then q = l * (1 + s) else q = l + s - l * s end | |
local p = 2 * l - q | |
local r = hue2rgb(p, q, h + 1/3) | |
local g = hue2rgb(p, q, h) | |
local b = hue2rgb(p, q, h - 1/3) | |
return round(r * 255), round(g * 255), round(b * 255) | |
end | |
end | |
end | |
out = io.stdout | |
local hsltab = {} | |
do | |
local hue_config = { | |
{ hue = 0, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 30, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 60, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 90, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 120, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 150, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 180, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 210, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 240, saturation = 3/4, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 270, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 300, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } }, | |
{ hue = 330, saturation = 2/3, levels = { 1/8, 1/4, 3/8, 1/2, 5/8 } } | |
} | |
for _, conf in ipairs(hue_config) do | |
for _, l in ipairs(conf.levels) do | |
local r, g, b = hsl2rgb(conf.hue, conf.saturation, l) | |
hsltab[#hsltab+1] = {h=conf.hue, s=conf.saturation, l=l, r=r, g=g, b=b} | |
end | |
end | |
end | |
do | |
local i = 1 | |
local N = #hsltab | |
while i < N do | |
local r1, b1, g1 = hsltab[i].r, hsltab[i].g, hsltab[i].b | |
local j = i + 1 | |
while j <= N do | |
local r2, b2, g2 = hsltab[j].r, hsltab[j].g, hsltab[j].b | |
if r1==r2 and b1==b2 and g1==g2 then | |
table.remove(hsltab, j) | |
N = N - 1 | |
end | |
j = j + 1 | |
end | |
i = i + 1 | |
end | |
end | |
out:write("GIMP Palette\nName: HuePalSorted\nColumns: 5\n#\n") | |
for i, v in ipairs(hsltab) do | |
out:write(string.format("%3i%4i%4i\tH%i S%i L%i\n", v.r, v.g, v.b, v.h, v.s*100, v.l*100)) | |
end | |
for i = 0, 9 do | |
local v = (i / 9.0) * 255.0 | |
out:write(string.format("%3i%4i%4i\tGRAY %i\n", v, v, v, v)) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GIMP Palette | |
Name: HuePalSorted | |
Columns: 5 | |
# | |
53 11 11 H0 S66 L12 | |
106 21 21 H0 S66 L25 | |
159 32 32 H0 S66 L37 | |
212 43 43 H0 S66 L50 | |
223 96 96 H0 S66 L62 | |
53 32 11 H30 S66 L12 | |
106 64 21 H30 S66 L25 | |
159 96 32 H30 S66 L37 | |
212 128 43 H30 S66 L50 | |
223 159 96 H30 S66 L62 | |
53 53 11 H60 S66 L12 | |
106 106 21 H60 S66 L25 | |
159 159 32 H60 S66 L37 | |
212 212 43 H60 S66 L50 | |
223 223 96 H60 S66 L62 | |
32 53 11 H90 S66 L12 | |
64 106 21 H90 S66 L25 | |
96 159 32 H90 S66 L37 | |
128 212 43 H90 S66 L50 | |
159 223 96 H90 S66 L62 | |
11 53 11 H120 S66 L12 | |
21 106 21 H120 S66 L25 | |
32 159 32 H120 S66 L37 | |
43 212 43 H120 S66 L50 | |
96 223 96 H120 S66 L62 | |
11 53 32 H150 S66 L12 | |
21 106 64 H150 S66 L25 | |
32 159 96 H150 S66 L37 | |
43 212 128 H150 S66 L50 | |
96 223 159 H150 S66 L62 | |
11 53 53 H180 S66 L12 | |
21 106 106 H180 S66 L25 | |
32 159 159 H180 S66 L37 | |
43 212 212 H180 S66 L50 | |
96 223 223 H180 S66 L62 | |
11 32 53 H210 S66 L12 | |
21 64 106 H210 S66 L25 | |
32 96 159 H210 S66 L37 | |
43 127 212 H210 S66 L50 | |
96 159 223 H210 S66 L62 | |
8 8 56 H240 S75 L12 | |
16 16 112 H240 S75 L25 | |
24 24 167 H240 S75 L37 | |
32 32 223 H240 S75 L50 | |
88 88 231 H240 S75 L62 | |
32 11 53 H270 S66 L12 | |
64 21 106 H270 S66 L25 | |
96 32 159 H270 S66 L37 | |
127 43 212 H270 S66 L50 | |
159 96 223 H270 S66 L62 | |
53 11 53 H300 S66 L12 | |
106 21 106 H300 S66 L25 | |
159 32 159 H300 S66 L37 | |
212 43 212 H300 S66 L50 | |
223 96 223 H300 S66 L62 | |
53 11 32 H330 S66 L12 | |
106 21 64 H330 S66 L25 | |
159 32 96 H330 S66 L37 | |
212 43 128 H330 S66 L50 | |
223 96 159 H330 S66 L62 | |
0 0 0 GRAY 0 | |
28 28 28 GRAY 28 | |
56 56 56 GRAY 56 | |
85 85 85 GRAY 85 | |
113 113 113 GRAY 113 | |
141 141 141 GRAY 141 | |
170 170 170 GRAY 170 | |
198 198 198 GRAY 198 | |
226 226 226 GRAY 226 | |
255 255 255 GRAY 255 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment