| 1 |
% DELAY.MF (RMCG19950405) |
| 2 |
|
| 3 |
% DELAY.MF delays the actual drawing till the endchar; |
| 4 |
% Copyright (C) 2003 Ram\'on Casares |
| 5 |
% |
| 6 |
% This program is free software; you can redistribute it and/or modify |
| 7 |
% it under the terms of the GNU General Public License as published by |
| 8 |
% the Free Software Foundation; either version 2 of the License, or |
| 9 |
% (at your option) any later version. |
| 10 |
% |
| 11 |
% This program is distributed in the hope that it will be useful, |
| 12 |
% but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
% GNU General Public License for more details. |
| 15 |
% |
| 16 |
% You should have received a copy of the GNU General Public License |
| 17 |
% along with this program; if not, write to the |
| 18 |
% Free Software Foundation, Inc., |
| 19 |
% 59 Temple Place, Suite 330, |
| 20 |
% Boston, MA 02111-1307 USA |
| 21 |
|
| 22 |
def clear_del = |
| 23 |
save _dn, _del; _dn := 0; string _del[]; |
| 24 |
enddef; |
| 25 |
|
| 26 |
def make_del = |
| 27 |
for k := 1 upto _dn: scantokens _del[k]; endfor |
| 28 |
enddef; |
| 29 |
|
| 30 |
extra_beginchar := extra_beginchar & "clear_del;"; |
| 31 |
extra_endchar := "make_del;" & extra_endchar; |
| 32 |
|
| 33 |
def MTlabel(suffix i)(expr v,h,add,wd,ht,dp) = |
| 34 |
x.i.l = x.i if h="c": - wd/2 elseif h="r": - wd fi; |
| 35 |
y.i.t = y.i if v="c": + ht/2 elseif v="b": + ht fi; |
| 36 |
x.i.r = x.i.l + wd; y.i.b = y.i.t - ht - dp; |
| 37 |
if not (add=""): _del[incr _dn] := "_delete(" & str i & ");"; fi |
| 38 |
_del[incr _dn] := "_pos(" & str i & ");"; |
| 39 |
enddef; |
| 40 |
|
| 41 |
def _delete(suffix i) = erase fill (x.i.l,y.i.t) -- |
| 42 |
(x.i.l,y.i.b) -- (x.i.r,y.i.b) -- (x.i.r,y.i.t) -- cycle; |
| 43 |
enddef; |
| 44 |
|
| 45 |
def _pos(suffix i) = |
| 46 |
message"\MTloglabel"; show x\i/pt; show y\i/pt; message""; |
| 47 |
enddef; |
| 48 |
|
| 49 |
pickup pencircle scaled 0.4pt; thin_pen:=savepen; |
| 50 |
pickup pencircle scaled 0.8pt; med_pen:=savepen; |
| 51 |
pickup pencircle scaled 1.2pt; thick_pen:=savepen; |
| 52 |
|
| 53 |
def thinpen = pickup thin_pen; |
| 54 |
_del[incr _dn] := "pickup thin_pen;"; |
| 55 |
enddef; |
| 56 |
|
| 57 |
def medpen = pickup med_pen; |
| 58 |
_del[incr _dn] := "pickup med_pen;"; |
| 59 |
enddef; |
| 60 |
|
| 61 |
def thickpen = pickup thick_pen; |
| 62 |
_del[incr _dn] := "pickup thick_pen;"; |
| 63 |
enddef; |
| 64 |
|
| 65 |
def rectangle(suffix s)(expr width,height) = |
| 66 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 67 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 68 |
_del[incr _dn] := "_rectangle(" & str s & ");"; |
| 69 |
enddef; |
| 70 |
|
| 71 |
def _rectangle(suffix s) = |
| 72 |
draw (x.s.l,y.s.b) -- (x.s.r,y.s.b) -- |
| 73 |
(x.s.r,y.s.t) -- (x.s.l,y.s.t) -- cycle; |
| 74 |
enddef; |
| 75 |
|
| 76 |
def square(suffix s)(expr side) = |
| 77 |
x.s.l = x.s - side/2; x.s.r = x.s + side/2; |
| 78 |
y.s.t = y.s + side/2; y.s.b = y.s - side/2; |
| 79 |
_del[incr _dn] := "_square(" & str s & ");"; |
| 80 |
enddef; |
| 81 |
|
| 82 |
def _square(suffix s) = |
| 83 |
draw (x.s.l,y.s.b) -- (x.s.r,y.s.b) -- |
| 84 |
(x.s.r,y.s.t) -- (x.s.l,y.s.t) -- cycle; |
| 85 |
enddef; |
| 86 |
|
| 87 |
def ellipse(suffix s)(expr width,height) = |
| 88 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 89 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 90 |
_del[incr _dn] := "_ellipse(" & str s & ");"; |
| 91 |
enddef; |
| 92 |
|
| 93 |
def _ellipse(suffix s) = |
| 94 |
draw (fullcircle xscaled (x.s.r - x.s.l) yscaled (y.s.t - y.s.b) |
| 95 |
shifted z.s); |
| 96 |
enddef; |
| 97 |
|
| 98 |
def circle(suffix s)(expr diameter) = |
| 99 |
x.s.l = x.s - diameter/2; x.s.r = x.s + diameter/2; |
| 100 |
y.s.t = y.s + diameter/2; y.s.b = y.s - diameter/2; |
| 101 |
_del[incr _dn] := "_circle(" & str s & ");"; |
| 102 |
enddef; |
| 103 |
|
| 104 |
def _circle(suffix s) = |
| 105 |
draw (fullcircle scaled (x.s.r - x.s.l) shifted z.s); |
| 106 |
enddef; |
| 107 |
|
| 108 |
def oval(suffix s)(expr width,height,superness) = |
| 109 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 110 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 111 |
x.s.ness = superness; |
| 112 |
_del[incr _dn] := "_oval(" & str s & ");"; |
| 113 |
enddef; |
| 114 |
|
| 115 |
def _oval(suffix s) = |
| 116 |
draw superellipse((x.s.r,y.s),(x.s,y.s.t),(x.s.l,y.s),(x.s,y.s.b), |
| 117 |
x.s.ness); |
| 118 |
enddef; |
| 119 |
|
| 120 |
def triangle(suffix s)(expr width,height) = |
| 121 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 122 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 123 |
_del[incr _dn] := "_triangle(" & str s & ");"; |
| 124 |
enddef; |
| 125 |
|
| 126 |
def _triangle(suffix s) = |
| 127 |
draw (x.s.l,y.s.b) -- (x.s.r,y.s.b) -- (x.s,y.s.t) -- cycle; |
| 128 |
enddef; |
| 129 |
|
| 130 |
def lozenge(suffix s)(expr width,height) = |
| 131 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 132 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 133 |
_del[incr _dn] := "_lozenge(" & str s & ");"; |
| 134 |
enddef; |
| 135 |
|
| 136 |
def _lozenge(suffix s) = |
| 137 |
draw (x.s.l,y.s) -- (x.s,y.s.b) -- |
| 138 |
(x.s.r,y.s) -- (x.s,y.s.t) -- cycle; |
| 139 |
enddef; |
| 140 |
|
| 141 |
dot_diameter := 2.4pt; |
| 142 |
|
| 143 |
def dot(suffix s) = |
| 144 |
x.s.dd = dot_diameter; |
| 145 |
_del[incr _dn] := "_dot(" & str s & ");"; |
| 146 |
enddef; |
| 147 |
|
| 148 |
def _dot(suffix s) = |
| 149 |
fill fullcircle scaled x.s.dd shifted z.s; |
| 150 |
enddef; |
| 151 |
|
| 152 |
def line(suffix s) = |
| 153 |
_del[incr _dn] := "_line(" & str s & ");"; |
| 154 |
enddef; |
| 155 |
|
| 156 |
def _line(suffix s) = |
| 157 |
draw z.s.o -- z.s.d; |
| 158 |
enddef; |
| 159 |
|
| 160 |
dash_length := 4pt; |
| 161 |
|
| 162 |
def dottedline(suffix s) = |
| 163 |
x.s.dl = dash_length; x.s.dd = dot_diameter; |
| 164 |
_del[incr _dn] := "_dottedline(" & str s & ");"; |
| 165 |
enddef; |
| 166 |
|
| 167 |
def _dottedline(suffix s) = |
| 168 |
begingroup save p, n; |
| 169 |
path p; p = z.s.o -- z.s.d; |
| 170 |
n := floor(length(z.s.d-z.s.o)/abs(x.s.dl)); |
| 171 |
for i := 0 upto n: |
| 172 |
fill fullcircle scaled x.s.dd shifted (point i/n of p); |
| 173 |
endfor endgroup |
| 174 |
enddef; |
| 175 |
|
| 176 |
def dashedline(suffix s) = |
| 177 |
x.s.dl = dash_length; |
| 178 |
_del[incr _dn] := "_dashedline(" & str s & ");"; |
| 179 |
enddef; |
| 180 |
|
| 181 |
def _dashedline(suffix s) = |
| 182 |
begingroup save p, n; |
| 183 |
path p; p = z.s.o -- z.s.d; |
| 184 |
n := floor(length(z.s.d-z.s.o)/abs(x.s.dl)); |
| 185 |
if not (odd n): n := n + 1; fi |
| 186 |
for i := 0 upto (n-1): if not (odd i): |
| 187 |
draw subpath(i/n,(i+1)/n) of p; |
| 188 |
fi endfor endgroup |
| 189 |
enddef; |
| 190 |
|
| 191 |
arrow_head_length := 6pt; |
| 192 |
arrow_head_width := 2.4pt; |
| 193 |
|
| 194 |
def arrowhead(suffix s) = |
| 195 |
x.s.ahl = arrow_head_length; x.s.ahw = arrow_head_width; |
| 196 |
_del[incr _dn] := "_arrowhead(" & str s & ");"; |
| 197 |
enddef; |
| 198 |
|
| 199 |
def _arrowhead(suffix s) = |
| 200 |
z.s.dh = (x.s.ahl/length(z.s.d-z.s.o))[z.s.d,z.s.o]; |
| 201 |
z.s.dr = z.s.dh + x.s.ahw / 2 * dir(angle(z.s.d-z.s.o)+90); |
| 202 |
z.s.dl = z.s.dh + x.s.ahw / 2 * dir(angle(z.s.d-z.s.o)-90); |
| 203 |
fill z.s.d -- z.s.dr -- z.s.dl -- cycle; |
| 204 |
enddef; |
| 205 |
|
| 206 |
def arrow(suffix s) = |
| 207 |
arrowhead(s); |
| 208 |
_del[incr _dn] := "_arrow(" & str s & ");"; |
| 209 |
enddef; |
| 210 |
|
| 211 |
def _arrow(suffix s) = |
| 212 |
draw z.s.o .. z.s.dh; |
| 213 |
enddef; |
| 214 |
|
| 215 |
def cillinder(suffix s)(expr width,height) = |
| 216 |
x.s.l = x.s - 1/2width; x.s.r = x.s + 1/2width; |
| 217 |
y.s.b = y.s - 1/2height; y.s.t = y.s + 1/2height; |
| 218 |
y.s.ar = 1/6height; |
| 219 |
_del[incr _dn] := "_cillinder(" & str s & ");"; |
| 220 |
enddef; |
| 221 |
|
| 222 |
def _cillinder(suffix s) = |
| 223 |
draw (x.s.l,y.s.t-y.s.ar) -- (x.s.l,y.s.b+y.s.ar); |
| 224 |
draw (x.s.r,y.s.t-y.s.ar) -- (x.s.r,y.s.b+y.s.ar); |
| 225 |
draw (x.s.l,y.s.b+y.s.ar){down} .. (x.s,y.s.b){right} |
| 226 |
.. (x.s.r,y.s.b+y.s.ar){up}; |
| 227 |
draw (x.s.l,y.s.t-y.s.ar){down} .. (x.s,y.s.t-2y.s.ar){right} |
| 228 |
.. (x.s.r,y.s.t-y.s.ar){up} .. (x.s,y.s.t){left} .. cycle; |
| 229 |
enddef; |
| 230 |
|
| 231 |
join_radius := 5pt; |
| 232 |
|
| 233 |
def box(suffix s)(expr width,height) = |
| 234 |
x.s.l = x.s - width/2; x.s.r = x.s + width/2; |
| 235 |
y.s.t = y.s + height/2; y.s.b = y.s - height/2; |
| 236 |
x.s.jr = join_radius; |
| 237 |
_del[incr _dn] := "_box(" & str s & ");"; |
| 238 |
enddef; |
| 239 |
|
| 240 |
def _box(suffix s) = |
| 241 |
if min((x.s.r-x.s.l),(y.s.t-y.s.b)) > 2x.s.jr: |
| 242 |
draw (((x.s,y.s.b) .. (x.s.r,y.s.b)) softjoin |
| 243 |
((x.s.r,y.s.b) .. (x.s.r,y.s.t)) softjoin |
| 244 |
((x.s.r,y.s.t) .. (x.s.l,y.s.t)) softjoin |
| 245 |
((x.s.l,y.s.t) .. (x.s.l,y.s.b)) softjoin |
| 246 |
((x.s.l,y.s.b) .. (x.s,y.s.b))); |
| 247 |
else: |
| 248 |
draw (fullcircle xscaled (x.s.r-x.s.l) yscaled (y.s.t-y.s.b) |
| 249 |
shifted z.s); |
| 250 |
fi |
| 251 |
enddef; |
| 252 |
|
| 253 |
def soft(suffix s) = |
| 254 |
_del[incr _dn] := "_soft(" & str s & ");"; |
| 255 |
enddef; |
| 256 |
|
| 257 |
def _soft(suffix s) = |
| 258 |
draw (z.s.o -- z.s.m) softjoin (z.s.m -- z.s.d); |
| 259 |
enddef; |
| 260 |
|
| 261 |
def softt(suffix s) = |
| 262 |
_del[incr _dn] := "_softt(" & str s & ");"; |
| 263 |
enddef; |
| 264 |
|
| 265 |
def _softt(suffix s) = |
| 266 |
draw ((z.s.o .. z.s.m1) softjoin |
| 267 |
(z.s.m1 .. z.s.m2) softjoin (z.s.m2 .. z.s.d)); |
| 268 |
enddef; |
| 269 |
|
| 270 |
def fork(suffix s) = |
| 271 |
z.s.head.o = z.s.m; z.s.head.d = z.s.d; |
| 272 |
arrowhead(s.head); |
| 273 |
dot(s.o); |
| 274 |
z.s.body.o = z.s.o; z.s.body.m = z.s.m; |
| 275 |
z.s.body.d = z.s.head.dh; |
| 276 |
soft(s.body); |
| 277 |
enddef; |
| 278 |
|
| 279 |
def darrow(suffix s) = |
| 280 |
z.s.med = 1/2[z.s.o,z.s.d]; |
| 281 |
z.s.one.o = z.s.med; z.s.one.d = z.s.d; |
| 282 |
arrow(s.one); |
| 283 |
z.s.two.o = z.s.med; z.s.two.d = z.s.o; |
| 284 |
arrow(s.two); |
| 285 |
enddef; |
| 286 |
|
| 287 |
def arroww(suffix s) = |
| 288 |
z.s.head.o = z.s.m; z.s.head.d = z.s.d; |
| 289 |
arrowhead(s.head); |
| 290 |
z.s.body.o = z.s.o; z.s.body.m = z.s.m; |
| 291 |
z.s.body.d = z.s.head.dh; |
| 292 |
soft(s.body); |
| 293 |
enddef; |
| 294 |
|
| 295 |
def arrowww(suffix s) = |
| 296 |
z.s.head.o = z.s.m2; z.s.head.d = z.s.d; |
| 297 |
arrowhead(s.head); |
| 298 |
z.s.body.o = z.s.o; z.s.body.m1 = z.s.m1; |
| 299 |
z.s.body.m2 = z.s.m2; z.s.body.d = z.s.head.dh; |
| 300 |
softt(s.body); |
| 301 |
enddef; |