Created
February 13, 2026 10:04
-
-
Save santhoshtr/f5b79aa56b2d3e652e233b5189991324 to your computer and use it in GitHub Desktop.
hsl_colors #metapost-sandbox
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
| vardef hsl_color(expr h, s, l) = | |
| save chroma, hh, x, m; | |
| chroma = (1 - abs(2 * l - 1)) * s; | |
| hh = h / 60; | |
| x = chroma * (1 - abs(hh mod 2 - 1)); | |
| m = l - chroma / 2; | |
| if hh < 1: (chroma,x,0)+(m,m,m) | |
| elseif hh < 2: (x,chroma,0)+(m,m,m) | |
| elseif hh < 3: (0,chroma,x)+(m,m,m) | |
| elseif hh < 4: (0,x,chroma)+(m,m,m) | |
| elseif hh < 5: (x,0,chroma)+(m,m,m) | |
| else: (chroma,0,x)+(m,m,m) | |
| fi | |
| enddef; | |
| beginfig(0); | |
| numeric s[], l[]; | |
| s0 = 0.5; l0 = 0.3; % First row: medium saturation, high lightness | |
| s1 = 0.75; l1 = 0.4; % Second row: high saturation, high lightness | |
| s2 = 1; l2 = 0.5; % Third row: high saturation, medium lightness | |
| path r; | |
| for y = 0, 1, 2: | |
| for h = 0 step 15 until 360: | |
| r := fullcircle scaled 24 shifted (h, -36 * y if y = 2: +8 fi); | |
| fill r withcolor hsl_color(h, s[y], l[y]); | |
| draw r withcolor white; | |
| endfor | |
| endfor | |
| label.urt("Less saturation", (-20, 14)); | |
| label.lrt("Lower lightness", (-20, -78)); | |
| drawarrow (-15, -21) -- (-15, 12); | |
| drawarrow (-15, -43) -- (-15, -76); | |
| endfig; | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment