summaryrefslogtreecommitdiff
path: root/info/examples/lgc2/4-1-5.mp
blob: 96ac30324f0012e0a36a47bc4ad856fcd5b5107a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
% --- 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;