% --- start of displayed preamble in the book ---
% p=picture
def draw_multipath(expr p) text options=
for i within p:
draw i options;
endfor;
enddef;
vardef addto_multipath(text p)(expr pa,thickness) text options=
save savepen;
pen savepen;
savepen=currentpen;
pickup pencircle scaled thickness;
addto p also image(draw pa options;);
currentpen:=savepen;
enddef;
% --- end of displayed preamble in the book ---
% graphic converted to gray in book using 'color2gray'
defaultfont:="ptmr8r";
warningcheck:=0;
beginfig(1)
numeric u;u=10mm;
path p[];picture pic;
p0=origin..(2u,0)..(4u,u)..(3u,2u)
...(2u,-u)..tension2..(u,3u);
n=20;
for i=1 upto n:
p[i]=subpath(((i-1)/n)*length(p0),
(i/n)*length(p0)) of p0;
endfor;
pic=nullpicture;
for i=1 upto n:
if odd i:
addto_multipath(pic)(p[i],2pt*i/n)
withcolor ((i/n)*red+(1-i/n)*blue);
else:
addto_multipath(pic)(p[i],3pt*(1-i/n))
withcolor ((i/n)*green+(1-i/n)*blue);
fi;
endfor;
draw_multipath(pic);
endfig;
end;