Debian Codegraph @

texmf-dist/doc/metapost/featpost/example/iamsorrykarl.mp

raw
1 % iamsorrykarl.mp
2 % 2006
3 % L. Nobre G.
4
5 %input featpost3Dplus2D;
6
7 % bash: export TEX=latex
8 % tcsh: setenv TEX latex
9
10 prologues := 1;
11
12 beginfig(1);
13 numeric u, nstripes, aspecratio, minskip, maxskip, shiftlim, shiftmin;
14 numeric nbreaks, i, j, ymax, shiftx, lefh, righ, actualx, newx;
15 numeric prevlefh, prevrigh, xmax, auxan, auxr, cdiam;
16 path lefp[], rigp[], strp[];
17 pair shif, reflef, refrig, auxa, auxb;
18 boolean exitcondition;
19 u = 1cm;
20 nstripes = 7;
21 aspecratio = 1.7;
22 minskip = 0.5u; % must not be too small
23 maxskip = 4u;
24 shiftlim = 0.7u;
25 shiftmin = 0.25u;
26 cdiam = 0.65u;
27 xmax = (2*nstripes-1)*u;
28 ymax = aspecratio*xmax;
29 prevlefh = ymax;
30 prevrigh = ymax;
31 actualx = u;
32 for i=1 upto nstripes:
33 lefp[i] = ((2*i-1)*u,ymax);
34 rigp[i] = ((2*i-1)*u,ymax)--(2*i*u,ymax);
35 endfor;
36 exitcondition = false;
37 forever:
38 auxr := uniformdeviate(2)-1;
39 if auxr > 0:
40 newx := actualx + shiftmin + (shiftlim-shiftmin)*auxr;
41 else:
42 newx := actualx - shiftmin + (shiftlim-shiftmin)*auxr;
43 fi;
44 lefh := prevlefh - minskip - uniformdeviate(maxskip-minskip);
45 righ := prevrigh - minskip - uniformdeviate(maxskip-minskip);
46 if lefh < minskip:
47 lefh := minskip;
48 exitcondition := true;
49 fi;
50 if righ < minskip:
51 righ := minskip;
52 exitcondition := true;
53 fi;
54 reflef := (newx,lefh);
55 refrig := (newx+xmax,righ);
56 auxan := angle(refrig-reflef);
57 shif := (newx-actualx)*(1,sind(auxan)/cosd(auxan));
58 for i=1 upto nstripes:
59 auxa := point (length lefp[i]) of lefp[i];
60 auxb := point (length rigp[i]) of rigp[i];
61 pair poil, poir;
62 poil = auxa+whatever*down;
63 poil = whatever[reflef,refrig];
64 poir = auxb+whatever*down;
65 poir = whatever[reflef,refrig];
66 lefp[i] := lefp[i]--poil--(poil+shif);
67 rigp[i] := rigp[i]--poir--(poir+shif);
68 endfor;
69 actualx := newx;
70 prevlefh := lefh;
71 prevrigh := righ;
72 exitif exitcondition;
73 endfor;
74 for i=1 upto nstripes:
75 auxa := point (length lefp[i]) of lefp[i];
76 auxb := point (length rigp[i]) of rigp[i];
77 pair poil, poir;
78 poil = auxa+whatever*down;
79 poil = whatever[origin,right];
80 poir = auxb+whatever*down;
81 poir = whatever[origin,right];
82 lefp[i] := lefp[i]--poil--poir;
83 rigp[i] := rigp[i]--poir;
84 strp[i] = buildcycle( lefp[i], reverse rigp[i] );
85 fill strp[i] withcolor red;
86 endfor;
87 % for i=nstripes+1 upto nstripes+50:
88 % strp[i] = fullcircle scaled cdiam shifted
89 % (uniformdeviate(xmax),uniformdeviate(ymax));
90 % fill strp[i];
91 % endfor;
92 endfig;
93
94 end.