1 % Examples for MetaPost doc, by John Hobby. Public domain.
3 filenametemplate "%j-%c.mps";
7 z0=(0,0); z1=(a,0); z2=(0,b);
8 z0=.5[z1,z3]=.5[z2,z4];
9 draw z1..z2..z3..z4..cycle;
12 label.top(btex $a$ etex, .5[z0,z1]);
13 label.lft(btex $b$ etex, .5[z0,z2]);
25 p[i] = (w/ii,h){1/ii,-1}...(w/i,h/i)...(w,h/ii){1,-1/ii};
28 q[i] = origin..(w,i*h) cutafter p1.5;
31 pp = buildcycle(q0.5, p2, q1.5, p4);
33 fill pp withcolor .8white;
35 picture lab; lab=thelabel(btex $f>0$ etex, z0);
36 unfill bbox lab; draw lab;
37 draw q0.5; draw p2; draw q1.5; draw p4;
38 makelabel.top(btex $P$ etex, p2 intersectionpoint q0.5);
39 makelabel.rt(btex $Q$ etex, p2 intersectionpoint q1.5);
49 # = .1; % Keep the function single-valued
50 fun = ((0,-1#)..(1,.5#){right}..(1.9,.2#){right}..{curl .1}(3.2,2#))
51 scaled scf yscaled(1/#);
53 vardef vertline primary x = (x,-infinity)..(x,infinity) enddef;
54 primarydef f atx x = (f intersectionpoint vertline x) enddef;
55 primarydef f whenx x = xpart(f intersectiontimes vertline x) enddef;
59 y2a=0; z1-z2a=whatever*direction fun whenx x1 of fun;
61 y3a=0; z2-z3a=whatever*direction fun whenx x2 of fun;
63 draw fun withpen pencircle scaled 1pt;
64 drawarrow (0,0)..(3.2scf,0);
66 label.bot(btex $x_1$ etex, z1a);
67 draw z1a..z1 dashed evenly;
68 makelabel(nullpicture, z1);
69 draw z1..z2a withpen pencircle scaled .3;
70 label.bot(btex $x_2$ etex, z2a);
71 draw z2a..z2 dashed evenly;
72 makelabel(nullpicture, z2);
73 draw z2..z3a withpen pencircle scaled .3;
74 label.bot(btex $x_3$ etex, z3a);
81 z[i]=(0,40i); z[i+3]-z[i]=(100,30);
83 pickup pencircle scaled 18;
84 def gray = withcolor .8white enddef;
86 linecap:=butt; draw z1..z4 gray;
87 linecap:=squared; draw z2..z5 gray;
88 dotlabels.top(0,1,2,3,4,5);
89 endfig; linecap:=rounded;
95 z[i]=(0,50i); z[i+3]-z[i]=(60,40);
98 pickup pencircle scaled 24;
99 def gray = withcolor .8white enddef;
100 draw z0--z3--z6 gray;
101 linejoin:=mitered; draw z1..z4--z7 gray;
102 linejoin:=beveled; draw z2..z5--z8 gray;
103 dotlabels.bot(0,1,2,3,4,5,6,7,8);
104 endfig; linejoin:=rounded;
112 fill unitsquare xscaled 1.1in yscaled .7in withcolor .9white;
113 boxit(currentpicture);
115 clearit; drawboxed();
116 forsuffixes $=n,c: makelabel.top(str $, $); endfor
117 makelabel.bot("s",s);
118 forsuffixes $=ne,e,se: makelabel.rt(str $, $); endfor
119 forsuffixes $=nw,w,sw: makelabel.lft(str $, $); endfor
120 pickup pencircle scaled .3bp;
121 vardef larrow@#(expr a, da, s) =
122 drawdblarrow a..a+da; label@#(s,a+.5da); enddef;
123 larrow.rt(n, (0,-dy), "dy");
124 larrow.rt(s, (0,dy), "dy");
125 larrow.top(e, (-dx,0), "dx");
126 larrow.top(w, (dx,0), "dx");
132 boxjoin(a.se=b.sw; a.ne=b.nw );
133 boxit.a(btex $\cdots$ etex);
134 boxit.ni(btex $n_i$ etex);
135 boxit.di(btex $d_i$ etex);
136 boxit.nii(btex $n_{i+1}$ etex);
137 boxit.dii(btex $d_{i+1}$ etex);
139 boxit.nk(btex $n_k$ etex);
140 boxit.dk(btex $d_k$ etex);
143 drawboxed(a,ni,di,nii,dii,aa,nk,dk);
144 label.lft("ndtable:", a.w);
146 boxjoin(a.sw=b.nw; a.se=b.ne);
147 interim defaultdy:=7;
151 boxit.bd(btex $\vdots$ etex);
155 ba.ne = a.sw - (15,10);
157 drawboxed(ba,bb,bc,bd,be,bf);
158 label.lft("hashtab:", ba.w);
160 def ndblock suffix $ =
161 boxjoin(a.sw=b.nw; a.se=b.ne);
162 forsuffixes $$=$a,$b,$c:
163 boxit$$(); ($$dx,$$dy)=(5.5,4);
170 nda.a.c - bb.c = ndb.a.c - nda.c.c = (whatever,0);
171 xpart ndb.c.se = xpart ndc.a.ne = xpart di.c;
172 ndc.a.c - be.c = (whatever,0);
174 drawboxes(nda.a,nda.b,nda.c, ndb.a,ndb.b,ndb.c, ndc.a,ndc.b,ndc.c);
176 drawarrow bb.c .. nda.a.w;
177 drawarrow be.c .. ndc.a.w;
178 drawarrow nda.c.c .. ndb.a.w;
179 drawarrow nda.a.c{right}..{curl0}ni.c cutafter bpath ni;
180 drawarrow nda.b.c{right}..{curl0}di.c cutafter bpath di;
181 drawarrow ndc.a.c{right}..{curl0}nii.c cutafter bpath nii;
182 drawarrow ndc.b.c{right}..{curl0}dii.c cutafter bpath dii;
183 drawarrow ndb.a.c{right}..nk.c cutafter bpath nk;
184 drawarrow ndb.b.c{right}..dk.c cutafter bpath dk;
187 y.ptr = ypart ndc.a.ne;
188 drawarrow subpath (0,.7) of (z.ptr..{left}ndc.c.c) dashed evenly;
189 label.rt(btex ndblock etex, z.ptr);
196 interim circmargin := .07in;
197 fill unitsquare xscaled 1.1in yscaled .7in withcolor .9white;
198 circleit(currentpicture);
200 clearit; drawboxed();
201 forsuffixes $=n,c: makelabel.top(str $, $); endfor
202 makelabel.bot("s",s);
203 makelabel.rt("e", e);
204 makelabel.lft("w", w);
205 pickup pencircle scaled .3bp;
206 vardef larrow@#(expr a, da, s) =
207 drawdblarrow a..a+da; label@#(s,a+.5da); enddef;
208 larrow.rt(n, (0,-dy), "dy");
209 larrow.rt(s, (0,dy), "dy");
210 larrow.top(e, (-dx,0), "dx");
211 larrow.top(w, (dx,0), "dx");
218 vardef cuta(suffix a,b) expr p =
219 drawarrow p cutbefore bpath.a cutafter bpath.b;
220 point .5*length p of p
223 vardef self@# expr p =
224 cuta(@#,@#) @#.c{curl0}..@#.c+p..{curl0}@#.c enddef;
226 verbatimtex \def\stk#1#2{$\displaystyle{\matrix{#1\cr#2\cr}}$} etex
227 circleit.aa("Start"); aa.dx=aa.dy;
228 circleit.bb(btex \stk B{(a|b)^*a} etex);
229 circleit.cc(btex \stk C{b^*} etex);
230 circleit.dd(btex \stk D{(a|b)^*ab} etex);
231 circleit.ee("Stop"); ee.dx=ee.dy;
234 bb.c-aa.c = dd.c-bb.c = ee.c-dd.c = (hsep,0);
235 cc.c-bb.c = (0,.8hsep);
236 xpart(ee.e - aa.w) = 3.8in;
237 drawboxed(aa,bb,cc,dd,ee);
239 label.ulft(btex$b$etex, cuta(aa,cc) aa.c{dir50}..cc.c);
240 label.top(btex$b$etex, self.cc(0,30pt));
241 label.rt(btex$a$etex, cuta(cc,bb) cc.c..bb.c);
242 label.top(btex$a$etex, cuta(aa,bb) aa.c..bb.c);
243 label.llft(btex$a$etex, self.bb(-20pt,-35pt));
244 label.top(btex$b$etex, cuta(bb,dd) bb.c..dd.c);
245 label.top(btex$b$etex, cuta(dd,ee) dd.c..ee.c);
246 label.lrt(btex$a$etex, cuta(dd,bb) dd.c..{dir140}bb.c);
247 label.bot(btex$a$etex, cuta(ee,bb) ee.c..tension1.3 ..{dir115}bb.c);
248 label.urt(btex$b$etex, cuta(ee,cc) ee.c{(cc.c-ee.c)rotated-15}..cc.c);