| 1 |
% Figures for MetaPost doc, by John Hobby. Public domain. |
| 2 |
|
| 3 |
input boxes |
| 4 |
|
| 5 |
if scantokens(mpversion) < 1.200: |
| 6 |
filenametemplate |
| 7 |
else: |
| 8 |
outputtemplate := |
| 9 |
fi |
| 10 |
"%j-%c.mps"; |
| 11 |
|
| 12 |
%%% This redefinition of dotlabel draws dots as a closed path |
| 13 |
%%% which are rendered more smoothly in Adobe Reader. |
| 14 |
vardef dotlabel@#(expr s,z) text t_ = |
| 15 |
label@#(s,z) t_; |
| 16 |
addto currentpicture |
| 17 |
contour (makepath pencircle scaled dotlabeldiam) shifted z t_; |
| 18 |
enddef; |
| 19 |
|
| 20 |
|
| 21 |
beginfig(48); |
| 22 |
fill unitsquare xscaled 1.1in yscaled .7in withcolor .9white; |
| 23 |
boxit(currentpicture); |
| 24 |
dx = dy = .25in; |
| 25 |
clearit; drawboxed(); |
| 26 |
forsuffixes $=n,c: makelabel.top(str $, $); endfor |
| 27 |
makelabel.bot("s",s); |
| 28 |
forsuffixes $=ne,e,se: makelabel.rt(str $, $); endfor |
| 29 |
forsuffixes $=nw,w,sw: makelabel.lft(str $, $); endfor |
| 30 |
pickup pencircle scaled .3bp; |
| 31 |
vardef larrow@#(expr a, da, s) = |
| 32 |
drawdblarrow a..a+da; label@#(s,a+.5da); enddef; |
| 33 |
larrow.rt(n, (0,-dy), "dy"); |
| 34 |
larrow.rt(s, (0,dy), "dy"); |
| 35 |
larrow.top(e, (-dx,0), "dx"); |
| 36 |
larrow.top(w, (dx,0), "dx"); |
| 37 |
endfig; |
| 38 |
|
| 39 |
|
| 40 |
beginfig(49); |
| 41 |
boxjoin(a.se=b.sw; a.ne=b.nw); |
| 42 |
boxit.a(btex\strut$\cdots$ etex); boxit.ni(btex\strut$n_i$ etex); |
| 43 |
boxit.di(btex\strut$d_i$ etex); boxit.ni1(btex\strut$n_{i+1}$ etex); |
| 44 |
boxit.di1(btex\strut$d_{i+1}$ etex); boxit.aa(btex\strut$\cdots$ etex); |
| 45 |
boxit.nk(btex\strut$n_k$ etex); boxit.dk(btex\strut$d_k$ etex); |
| 46 |
drawboxed(di,a,ni,ni1,di1,aa,nk,dk); label.lft("ndtable:", a.w); |
| 47 |
interim defaultdy:=7bp; |
| 48 |
boxjoin(a.sw=b.nw; a.se=b.ne); |
| 49 |
boxit.ba(); boxit.bb(); boxit.bc(); |
| 50 |
boxit.bd(btex $\vdots$ etex); boxit.be(); boxit.bf(); |
| 51 |
bd.dx=8bp; ba.ne=a.sw-(15bp,10bp); |
| 52 |
drawboxed(ba,bb,bc,bd,be,bf); label.lft("hashtab:",ba.w); |
| 53 |
vardef ndblock suffix $ = |
| 54 |
boxjoin(a.sw=b.nw; a.se=b.ne); |
| 55 |
forsuffixes $$=$1,$2,$3: boxit$$(); ($$dx,$$dy)=(5.5bp,4bp); |
| 56 |
endfor; enddef; |
| 57 |
ndblock nda; ndblock ndb; ndblock ndc; |
| 58 |
nda1.c-bb.c = ndb1.c-nda3.c = (whatever,0); |
| 59 |
xpart ndb3.se = xpart ndc1.ne = xpart di.c; |
| 60 |
ndc1.c - be.c = (whatever,0); |
| 61 |
drawboxed(nda1,nda2,nda3, ndb1,ndb2,ndb3, ndc1,ndc2,ndc3); |
| 62 |
drawarrow bb.c -- nda1.w; |
| 63 |
drawarrow be.c -- ndc1.w; |
| 64 |
drawarrow nda3.c -- ndb1.w; |
| 65 |
drawarrow nda1.c{right}..{curl0}ni.c cutafter bpath ni; |
| 66 |
drawarrow nda2.c{right}..{curl0}di.c cutafter bpath di; |
| 67 |
drawarrow ndc1.c{right}..{curl0}ni1.c cutafter bpath ni1; |
| 68 |
drawarrow ndc2.c{right}..{curl0}di1.c cutafter bpath di1; |
| 69 |
drawarrow ndb1.c{right}..nk.c cutafter bpath nk; |
| 70 |
drawarrow ndb2.c{right}..dk.c cutafter bpath dk; |
| 71 |
x.ptr=xpart aa.c; y.ptr=ypart ndc1.ne; |
| 72 |
drawarrow subpath (0,.7) of (z.ptr..{left}ndc3.c) dashed evenly; |
| 73 |
label.rt(btex \strut ndblock etex, z.ptr); endfig; |
| 74 |
|
| 75 |
|
| 76 |
\beginfig(50) |
| 77 |
interim circmargin := .07in; |
| 78 |
fill unitsquare xscaled 1.1in yscaled .7in withcolor .9white; |
| 79 |
circleit(currentpicture); |
| 80 |
dx = dy; |
| 81 |
clearit; drawboxed(); |
| 82 |
forsuffixes $=n,c: makelabel.top(str $, $); endfor |
| 83 |
makelabel.bot("s",s); |
| 84 |
makelabel.rt("e", e); |
| 85 |
makelabel.lft("w", w); |
| 86 |
pickup pencircle scaled .3bp; |
| 87 |
vardef larrow@#(expr a, da, s) = |
| 88 |
drawdblarrow a..a+da; label@#(s,a+.5da); enddef; |
| 89 |
larrow.rt(n, (0,-dy), "dy"); |
| 90 |
larrow.rt(s, (0,dy), "dy"); |
| 91 |
larrow.top(e, (-dx,0), "dx"); |
| 92 |
larrow.top(w, (dx,0), "dx"); |
| 93 |
endfig; |
| 94 |
|
| 95 |
|
| 96 |
vardef drawshadowed(text t) = |
| 97 |
fixsize(t); |
| 98 |
forsuffixes s=t: |
| 99 |
fill bpath.s shifted (1pt,-1pt); |
| 100 |
unfill bpath.s; |
| 101 |
drawboxed(s); |
| 102 |
endfor |
| 103 |
enddef; |
| 104 |
|
| 105 |
beginfig(51) |
| 106 |
circleit.a(btex Box 1 etex); |
| 107 |
circleit.b(btex Box 2 etex); |
| 108 |
b.n = a.s - (0,20pt); |
| 109 |
drawshadowed(a,b); |
| 110 |
drawarrow a.s -- b.n; |
| 111 |
endfig; |
| 112 |
|
| 113 |
|
| 114 |
vardef cuta(suffix a,b) expr p = |
| 115 |
drawarrow p cutbefore bpath.a cutafter bpath.b; |
| 116 |
point .5*length p of p |
| 117 |
enddef; |
| 118 |
|
| 119 |
vardef self@# expr p = |
| 120 |
cuta(@#,@#) @#.c{curl0}..@#.c+p..{curl0}@#.c enddef; |
| 121 |
|
| 122 |
beginfig(52); |
| 123 |
verbatimtex \def\stk#1#2{$\displaystyle{\matrix{#1\cr#2\cr}}$} etex |
| 124 |
circleit.aa(btex\strut Start etex); aa.dx=aa.dy; |
| 125 |
circleit.bb(btex \stk B{(a|b)^*a} etex); |
| 126 |
circleit.cc(btex \stk C{b^*} etex); |
| 127 |
circleit.dd(btex \stk D{(a|b)^*ab} etex); |
| 128 |
circleit.ee(btex\strut Stop etex); ee.dx=ee.dy; |
| 129 |
numeric hsep; |
| 130 |
bb.c-aa.c = dd.c-bb.c = ee.c-dd.c = (hsep,0); |
| 131 |
cc.c-bb.c = (0,.8hsep); |
| 132 |
xpart(ee.e - aa.w) = 3.8in; |
| 133 |
drawboxed(aa,bb,cc,dd,ee); |
| 134 |
label.ulft(btex$b$etex, cuta(aa,cc) aa.c{dir50}..cc.c); |
| 135 |
label.top(btex$b$etex, self.cc(0,30pt)); |
| 136 |
label.rt(btex$a$etex, cuta(cc,bb) cc.c..bb.c); |
| 137 |
label.top(btex$a$etex, cuta(aa,bb) aa.c..bb.c); |
| 138 |
label.llft(btex$a$etex, self.bb(-20pt,-35pt)); |
| 139 |
label.top(btex$b$etex, cuta(bb,dd) bb.c..dd.c); |
| 140 |
label.top(btex$b$etex, cuta(dd,ee) dd.c..ee.c); |
| 141 |
label.lrt(btex$a$etex, cuta(dd,bb) dd.c..{dir140}bb.c); |
| 142 |
label.bot(btex$a$etex, cuta(ee,bb) ee.c..tension1.3 ..{dir115}bb.c); |
| 143 |
label.urt(btex$b$etex, cuta(ee,cc) ee.c{(cc.c-ee.c)rotated-15}..cc.c); |
| 144 |
endfig; |
| 145 |
|
| 146 |
end |