Auteurs ou autrices : John D. Hobby, MetaPost development team.
Mise en ligne le 13 janvier 2023
Cet exemple est extrait de la documentation de MetaPost.
Code
def getmid(suffix p) =
pair p.mid[], p.off[], p.dir[];
for i=0 upto 36:
p.dir[i] = dir(5*i);
p.mid[i]+p.off[i] = directionpoint p.dir[i] of p;
p.mid[i]-p.off[i] = directionpoint -p.dir[i] of p;
endfor
enddef;
def joinup(suffix pt, d)(expr n) =
begingroup
save res, g; path res;
res = pt[0]{d[0]};
for i=1 upto n:
g:= if (pt[i]-pt[i-1]) dotprod d[i] <0: - fi 1;
res := res{g*d[i-1]}...{g*d[i]}pt[i];
endfor
res
endgroup
enddef;
beginfig(45)
path p, q;
p = ((5,2)...(3,4)...(1,3)...(-2,-3)...(0,-5)...(3,-4)
...(5,-3)...cycle) scaled .3cm shifted (0,5cm);
getmid(p);
draw p;
draw joinup(p.mid, p.dir, 36)..cycle;
q = joinup(p.off, p.dir, 36);
draw q..(q rotated 180)..cycle;
drawoptions(dashed evenly);
for i=0 upto 3:
draw p.mid[9i]-p.off[9i]..p.mid[9i]+p.off[9i];
draw -p.off[9i]..p.off[9i];
endfor
endfig;
end.