Skip to content

Instantly share code, notes, and snippets.

@dohyunkim
Last active August 10, 2026 21:30
Show Gist options
  • Select an option

  • Save dohyunkim/4ef0dd879313c67f7f3a69062d72caf7 to your computer and use it in GitHub Desktop.

Select an option

Save dohyunkim/4ef0dd879313c67f7f3a69062d72caf7 to your computer and use it in GitHub Desktop.
shadow effect with coons patch shading
\documentclass{article}
\usepackage{luamplib}
\pagestyle{empty}
\begin{document}
\mpfig*
numeric sh, wd, ht;
sh = 6; wd = 200; ht = 100;
path p[];
p1 = unitsquare xscaled wd yscaled ht;
p2 = unitsquare xscaled (wd-sh) yscaled sh shifted(sh,-sh);
p3 = unitsquare xscaled sh yscaled (ht-sh) shifted(wd,0);
p4 = (origin -- subpath (4,6) of fullcircle -- cycle) scaled 2sh shifted(sh,0);
p5 = (origin -- subpath (6,8) of fullcircle -- cycle) scaled 2sh shifted(wd,0);
p6 = (origin -- subpath (0,2) of fullcircle -- cycle) scaled 2sh shifted(wd,ht-sh);
\endmpfig
\mplibgroup{mymask}[asgroup="masking"]
\mpfig
fill boundingbox(p4--p6)
withshadingmethod "coons"
withcoonspatchinit(p2, 0, 0, 1/2, 1/2)
withcoonspatchinit(p3, 1/2, 0, 0, 1/2)
withcoonspatchinit(p4, 1/2, 0, 0, 0)
withcoonspatchinit(p5, 1/2, 0, 0, 0)
withcoonspatchinit(p6, 1/2, 0, 0, 0)
;
\endmpfig
\endmplibgroup
\mpfig
fill p1 withcolor 1/2[red,white];
fill boundingbox(p4--p6) withmaskinggroup "mymask";
\endmpfig
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment