\documentclass{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
vardef meander expr p =
save a, u, v, d, dy; numeric a, u, v, d; pair dy;
d = 4 xpart urcorner makepath currentpen;
a = arclength p; v = round(a/8d); u = a if v > 1: / v fi;
if not cycle p: point 0 of p -- fi for t = 0 step u until a-4eps:
hide(dy := d*unitvector(direction arctime t+1/2u of p of p rotated 90))
subpath(arctime t of p, arctime t+u-2d of p) of p shifted 3dy
--
subpath(arctime t+u-2d of p, arctime t+1/2 u of p) of p shifted -dy
--
subpath(arctime t+1/2u of p, arctime t+2d of p) of p shifted dy
--
subpath(arctime t+2d of p, arctime t+u of p) of p shifted -3dy
--
endfor if cycle p: cycle else: point infinity of p fi
enddef;