Skip to content

Instantly share code, notes, and snippets.

@santhoshtr
Created February 13, 2026 10:04
Show Gist options
  • Select an option

  • Save santhoshtr/b99412b51abdc353ff16f84f92024795 to your computer and use it in GitHub Desktop.

Select an option

Save santhoshtr/b99412b51abdc353ff16f84f92024795 to your computer and use it in GitHub Desktop.
hsv_colors #metapost-sandbox
% 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