Created
February 13, 2026 10:04
-
-
Save santhoshtr/b99412b51abdc353ff16f84f92024795 to your computer and use it in GitHub Desktop.
hsv_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
| % based on https://tug.ctan.org/info/drawing-with-metapost/Drawing-with-Metapost.pdf | |
| vardef hsv_color(expr h, s, v) = | |
| save chroma, hh, x, m; | |
| chroma = v * s; | |
| hh = h / 60; | |
| x = chroma * (1 - abs(hh mod 2 - 1)); | |
| m = v - chroma; | |
| 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[], v[]; | |
| s0 = 1/2; v0 = 7/8; | |
| s1 = 7/8; v1 = 7/8; | |
| s2 = 7/8; v2 = 1/2; | |
| path r; | |
| for y=0, 1, 2: | |
| for h=0 step 15 until 360: | |
| r := fullcircle scaled 24 shifted (h, -36y if y=2: +8 fi); | |
| fill r withcolor hsv_color(h, s[y], v[y]); | |
| draw r withcolor white; | |
| endfor | |
| endfor | |
| label.urt("Less saturation", (-20,14)); | |
| label.lrt("Lower value", (-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