% --- start of displayed preamble in the book --- vardef reflectray(expr s,a,p)= save tI,tn,ia,I,J;pair I,J; tI=xpart(p intersectiontimes (s--(s+30cm*dir(a)))); if tI>=0: I=point tI of p;draw s--I; tn=angle(direction tI of p)+90; %drawarrow I--(I+dir(tn)*3cm); % normal %drawarrow I--(I+dir(180+tn)*3cm); ia=tn-angle(s-I);J=I+dir(tn+ia)*2cm; draw I--J withcolor blue; fi; enddef; % --- end of displayed preamble in the book --- defaultfont:="ptmr8r"; warningcheck:=0; beginfig(1) numeric u;u=3mm;path p; p=((5u,-6u)..(4u,-2u)..(4.5u,0)..(5u,5u)) rotated 90; z0=origin; for a=40 step 5 until 140: reflectray(z0,a,p); endfor; draw p withcolor red; endfig; end;