| 1 |
% $Id: plain.mp,v 1.3 2005/04/28 06:45:21 taco Exp $ |
| 2 |
% Public domain. |
| 3 |
|
| 4 |
% This file gives the macros for plain MetaPost |
| 5 |
% It contains all the features of plain METAFONT except those specific to |
| 6 |
% font-making. (See The METAFONTbook by D.E. Knuth). |
| 7 |
% There are also a number of macros for labeling figures, etc. |
| 8 |
string base_name, base_version; base_name="plain"; base_version="1.005"; |
| 9 |
|
| 10 |
message "Preloading the plain mem file, version "&base_version; |
| 11 |
|
| 12 |
delimiters (); % this makes parentheses behave like parentheses |
| 13 |
def upto = step 1 until enddef; % syntactic sugar |
| 14 |
def downto = step -1 until enddef; |
| 15 |
def exitunless expr c = exitif not c enddef; |
| 16 |
let relax = \; % ignore the word `relax', as in TeX |
| 17 |
let \\ = \; % double relaxation is like single |
| 18 |
def ]] = ] ] enddef; % right brackets should be loners |
| 19 |
def -- = {curl 1}..{curl 1} enddef; |
| 20 |
def --- = .. tension infinity .. enddef; |
| 21 |
def ... = .. tension atleast 1 .. enddef; |
| 22 |
|
| 23 |
def gobble primary g = enddef; |
| 24 |
primarydef g gobbled gg = enddef; |
| 25 |
def hide(text t) = exitif numeric begingroup t;endgroup; enddef; |
| 26 |
def ??? = hide(interim showstopping:=1; showdependencies) enddef; |
| 27 |
def stop expr s = message s; gobble readstring enddef; |
| 28 |
|
| 29 |
warningcheck:=1; |
| 30 |
tracinglostchars:=1; |
| 31 |
|
| 32 |
def interact = % sets up to make "show" commands stop |
| 33 |
hide(showstopping:=1; tracingonline:=1) enddef; |
| 34 |
|
| 35 |
def loggingall = % puts tracing info into the log |
| 36 |
tracingcommands:=3; tracingtitles:=1; tracingequations:=1; |
| 37 |
tracingcapsules:=1; tracingspecs:=2; tracingchoices:=1; tracinglostchars:=1; |
| 38 |
tracingstats:=1; tracingoutput:=1; tracingmacros:=1; tracingrestores:=1; |
| 39 |
enddef; |
| 40 |
|
| 41 |
def tracingall = % turns on every form of tracing |
| 42 |
tracingonline:=1; showstopping:=1; loggingall enddef; |
| 43 |
|
| 44 |
def tracingnone = % turns off every form of tracing |
| 45 |
tracingcommands:=0; tracingtitles:=0; tracingequations:=0; |
| 46 |
tracingcapsules:=0; tracingspecs:=0; tracingchoices:=0; tracinglostchars:=0; |
| 47 |
tracingstats:=0; tracingoutput:=0; tracingmacros:=0; tracingrestores:=0; |
| 48 |
enddef; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
%% dash patterns |
| 53 |
|
| 54 |
vardef dashpattern(text t) = |
| 55 |
save on, off, w; |
| 56 |
let on=_on_; |
| 57 |
let off=_off_; |
| 58 |
w = 0; |
| 59 |
nullpicture t |
| 60 |
enddef; |
| 61 |
|
| 62 |
tertiarydef p _on_ d = |
| 63 |
begingroup save pic; |
| 64 |
picture pic; pic=p; |
| 65 |
addto pic doublepath (w,w)..(w+d,w); |
| 66 |
w := w+d; |
| 67 |
pic shifted (0,d) |
| 68 |
endgroup |
| 69 |
enddef; |
| 70 |
|
| 71 |
tertiarydef p _off_ d = |
| 72 |
begingroup w:=w+d; |
| 73 |
p shifted (0,d) |
| 74 |
endgroup |
| 75 |
enddef; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
%% basic constants and mathematical macros |
| 80 |
|
| 81 |
% numeric constants |
| 82 |
newinternal eps,epsilon,infinity,_; |
| 83 |
eps := .00049; % this is a pretty small positive number |
| 84 |
epsilon := 1/256/256; % but this is the smallest |
| 85 |
infinity := 4095.99998; % and this is the largest |
| 86 |
_ := -1; % internal constant to make macros unreadable but shorter |
| 87 |
|
| 88 |
newinternal mitered, rounded, beveled, butt, squared; |
| 89 |
mitered:=0; rounded:=1; beveled:=2; % linejoin types |
| 90 |
butt:=0; rounded:=1; squared:=2; % linecap types |
| 91 |
|
| 92 |
|
| 93 |
% pair constants |
| 94 |
pair right,left,up,down,origin; |
| 95 |
origin=(0,0); up=-down=(0,1); right=-left=(1,0); |
| 96 |
|
| 97 |
% path constants |
| 98 |
path quartercircle,halfcircle,fullcircle,unitsquare; |
| 99 |
fullcircle = makepath pencircle; |
| 100 |
halfcircle = subpath (0,4) of fullcircle; |
| 101 |
quartercircle = subpath (0,2) of fullcircle; |
| 102 |
unitsquare=(0,0)--(1,0)--(1,1)--(0,1)--cycle; |
| 103 |
|
| 104 |
% transform constants |
| 105 |
transform identity; |
| 106 |
for z=origin,right,up: z transformed identity = z; endfor |
| 107 |
|
| 108 |
% color constants |
| 109 |
color black, white, red, green, blue, background; |
| 110 |
black = (0,0,0); |
| 111 |
white = (1,1,1); |
| 112 |
red = (1,0,0); |
| 113 |
green = (0,1,0); |
| 114 |
blue = (0,0,1); |
| 115 |
background = white; % The user can reset this |
| 116 |
|
| 117 |
% color part selection for within |
| 118 |
def colorpart primary t = |
| 119 |
if colormodel t=7: |
| 120 |
(cyanpart t, magentapart t, yellowpart t, blackpart t) |
| 121 |
elseif colormodel t=5: |
| 122 |
(redpart t, greenpart t, bluepart t) |
| 123 |
elseif colormodel t=3: |
| 124 |
(greypart t) |
| 125 |
elseif colormodel t=1: |
| 126 |
false |
| 127 |
else: |
| 128 |
%%% For clipping and bounding paths, etc. |
| 129 |
if defaultcolormodel=7: (0,0,0,1) |
| 130 |
elseif defaultcolormodel=5: black |
| 131 |
elseif defaultcolormodel=3: 0 |
| 132 |
else: false |
| 133 |
fi |
| 134 |
fi |
| 135 |
enddef; |
| 136 |
|
| 137 |
% picture constants |
| 138 |
picture blankpicture,evenly,withdots; |
| 139 |
blankpicture=nullpicture; % `display blankpicture...' |
| 140 |
evenly=dashpattern(on 3 off 3); % `dashed evenly' |
| 141 |
withdots=dashpattern(off 2.5 on 0 off 2.5); % `dashed withdots' |
| 142 |
|
| 143 |
% string constants |
| 144 |
string ditto, EOF; |
| 145 |
ditto = char 34; % ASCII double-quote mark |
| 146 |
EOF = char 0; % end-of-file for readfrom and write..to |
| 147 |
|
| 148 |
% pen constants |
| 149 |
pen pensquare,penrazor,penspeck; |
| 150 |
pensquare = makepen(unitsquare shifted -(.5,.5)); |
| 151 |
penrazor = makepen((-.5,0)--(.5,0)--cycle); |
| 152 |
penspeck=pensquare scaled eps; |
| 153 |
|
| 154 |
% nullary operators |
| 155 |
vardef whatever = save ?; ? enddef; |
| 156 |
|
| 157 |
% unary operators |
| 158 |
let abs = length; |
| 159 |
|
| 160 |
vardef round primary u = |
| 161 |
if numeric u: floor(u+.5) |
| 162 |
elseif pair u: (round xpart u, round ypart u) |
| 163 |
else: u fi enddef; |
| 164 |
|
| 165 |
vardef ceiling primary x = -floor(-x) enddef; |
| 166 |
|
| 167 |
vardef byte primary s = |
| 168 |
if string s: ASCII fi s enddef; |
| 169 |
|
| 170 |
vardef dir primary d = right rotated d enddef; |
| 171 |
|
| 172 |
vardef unitvector primary z = z/abs z enddef; |
| 173 |
|
| 174 |
vardef inverse primary T = |
| 175 |
transform T_; T_ transformed T = identity; T_ enddef; |
| 176 |
|
| 177 |
vardef counterclockwise primary c = |
| 178 |
if turningnumber c <= 0: reverse fi c enddef; |
| 179 |
|
| 180 |
vardef tensepath expr r = |
| 181 |
for k=0 upto length r - 1: point k of r --- endfor |
| 182 |
if cycle r: cycle else: point infinity of r fi enddef; |
| 183 |
|
| 184 |
vardef center primary p = .5[llcorner p, urcorner p] enddef; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
% binary operators |
| 189 |
|
| 190 |
primarydef x mod y = (x-y*floor(x/y)) enddef; |
| 191 |
primarydef x div y = floor(x/y) enddef; |
| 192 |
primarydef w dotprod z = (xpart w * xpart z + ypart w * ypart z) enddef; |
| 193 |
|
| 194 |
primarydef x**y = if y=2: x*x else: takepower y of x fi enddef; |
| 195 |
def takepower expr y of x = |
| 196 |
if x>0: mexp(y*mlog x) |
| 197 |
elseif (x=0) and (y>0): 0 |
| 198 |
else: 1 |
| 199 |
if y=floor y: |
| 200 |
if y>=0: for n=1 upto y: *x endfor |
| 201 |
else: for n=_ downto y: /x endfor |
| 202 |
fi |
| 203 |
else: hide(errmessage "Undefined power: " & decimal x&"**"&decimal y) |
| 204 |
fi fi enddef; |
| 205 |
|
| 206 |
vardef direction expr t of p = |
| 207 |
postcontrol t of p - precontrol t of p enddef; |
| 208 |
|
| 209 |
vardef directionpoint expr z of p = |
| 210 |
a_:=directiontime z of p; |
| 211 |
if a_<0: errmessage("The direction doesn't occur"); fi |
| 212 |
point a_ of p enddef; |
| 213 |
|
| 214 |
secondarydef p intersectionpoint q = |
| 215 |
begingroup save x_,y_; (x_,y_)=p intersectiontimes q; |
| 216 |
if x_<0: errmessage("The paths don't intersect"); origin |
| 217 |
else: .5[point x_ of p, point y_ of q] fi endgroup |
| 218 |
enddef; |
| 219 |
|
| 220 |
tertiarydef p softjoin q = |
| 221 |
begingroup c_:=fullcircle scaled 2join_radius shifted point 0 of q; |
| 222 |
a_:=ypart(c_ intersectiontimes p); b_:=ypart(c_ intersectiontimes q); |
| 223 |
if a_<0:point 0 of p{direction 0 of p} else: subpath(0,a_) of p fi |
| 224 |
... if b_<0:{direction infinity of q}point infinity of q |
| 225 |
else: subpath(b_,infinity) of q fi endgroup enddef; |
| 226 |
newinternal join_radius,a_,b_; path c_; |
| 227 |
|
| 228 |
|
| 229 |
path cuttings; % what got cut off |
| 230 |
|
| 231 |
tertiarydef a cutbefore b = % tries to cut as little as possible |
| 232 |
begingroup save t; |
| 233 |
(t, whatever) = a intersectiontimes b; |
| 234 |
if t<0: |
| 235 |
cuttings:=point 0 of a; |
| 236 |
a |
| 237 |
else: cuttings:= subpath (0,t) of a; |
| 238 |
subpath (t,length a) of a |
| 239 |
fi |
| 240 |
endgroup |
| 241 |
enddef; |
| 242 |
|
| 243 |
tertiarydef a cutafter b = |
| 244 |
reverse (reverse a cutbefore b) |
| 245 |
hide(cuttings:=reverse cuttings) |
| 246 |
enddef; |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
% special operators |
| 251 |
vardef incr suffix $ = $:=$+1; $ enddef; |
| 252 |
vardef decr suffix $ = $:=$-1; $ enddef; |
| 253 |
|
| 254 |
def reflectedabout(expr w,z) = % reflects about the line w..z |
| 255 |
transformed |
| 256 |
begingroup transform T_; |
| 257 |
w transformed T_ = w; z transformed T_ = z; |
| 258 |
xxpart T_ = -yypart T_; xypart T_ = yxpart T_; % T_ is a reflection |
| 259 |
T_ endgroup enddef; |
| 260 |
|
| 261 |
def rotatedaround(expr z, d) = % rotates d degrees around z |
| 262 |
shifted -z rotated d shifted z enddef; |
| 263 |
let rotatedabout = rotatedaround; % for roundabout people |
| 264 |
|
| 265 |
vardef min(expr u)(text t) = % t is a list of numerics, pairs, or strings |
| 266 |
save u_; setu_ u; for uu = t: if uu<u_: u_:=uu; fi endfor |
| 267 |
u_ enddef; |
| 268 |
|
| 269 |
vardef max(expr u)(text t) = % t is a list of numerics, pairs, or strings |
| 270 |
save u_; setu_ u; for uu = t: if uu>u_: u_:=uu; fi endfor |
| 271 |
u_ enddef; |
| 272 |
|
| 273 |
def setu_ primary u = |
| 274 |
if pair u: pair u_ elseif string u: string u_ fi; |
| 275 |
u_=u enddef; |
| 276 |
|
| 277 |
def flex(text t) = % t is a list of pairs |
| 278 |
hide(n_:=0; for z=t: z_[incr n_]:=z; endfor |
| 279 |
dz_:=z_[n_]-z_1) |
| 280 |
z_1 for k=2 upto n_-1: ...z_[k]{dz_} endfor ...z_[n_] enddef; |
| 281 |
newinternal n_; pair z_[],dz_; |
| 282 |
|
| 283 |
def superellipse(expr r,t,l,b,s)= |
| 284 |
r{up}...(s[xpart t,xpart r],s[ypart r,ypart t]){t-r}... |
| 285 |
t{left}...(s[xpart t,xpart l],s[ypart l,ypart t]){l-t}... |
| 286 |
l{down}...(s[xpart b,xpart l],s[ypart l,ypart b]){b-l}... |
| 287 |
b{right}...(s[xpart b,xpart r],s[ypart r,ypart b]){r-b}...cycle enddef; |
| 288 |
|
| 289 |
vardef interpath(expr a,p,q) = |
| 290 |
for t=0 upto length p-1: a[point t of p, point t of q] |
| 291 |
..controls a[postcontrol t of p, postcontrol t of q] |
| 292 |
and a[precontrol t+1 of p, precontrol t+1 of q] .. endfor |
| 293 |
if cycle p: cycle |
| 294 |
else: a[point infinity of p, point infinity of q] fi enddef; |
| 295 |
|
| 296 |
vardef solve@#(expr true_x,false_x)= % @#(true_x)=true, @#(false_x)=false |
| 297 |
tx_:=true_x; fx_:=false_x; |
| 298 |
forever: x_:=.5[tx_,fx_]; exitif abs(tx_-fx_)<=tolerance; |
| 299 |
if @#(x_): tx_ else: fx_ fi :=x_; endfor |
| 300 |
x_ enddef; % now x_ is near where @# changes from true to false |
| 301 |
newinternal tolerance, tx_,fx_,x_; tolerance:=.01; |
| 302 |
|
| 303 |
vardef buildcycle(text ll) = |
| 304 |
save ta_, tb_, k_, i_, pp_; path pp_[]; |
| 305 |
k_=0; |
| 306 |
for q=ll: pp_[incr k_]=q; endfor |
| 307 |
i_=k_; |
| 308 |
for i=1 upto k_: |
| 309 |
(ta_[i], length pp_[i_]-tb_[i_]) = |
| 310 |
pp_[i] intersectiontimes reverse pp_[i_]; |
| 311 |
if ta_[i]<0: |
| 312 |
errmessage("Paths "& decimal i &" and "& decimal i_ &" don't intersect"); |
| 313 |
fi |
| 314 |
i_ := i; |
| 315 |
endfor |
| 316 |
for i=1 upto k_: subpath (ta_[i],tb_[i]) of pp_[i] .. endfor |
| 317 |
cycle |
| 318 |
enddef; |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
%% units of measure |
| 323 |
|
| 324 |
mm=2.83464; pt=0.99626; dd=1.06601; bp:=1; |
| 325 |
cm=28.34645; pc=11.95517; cc=12.79213; in:=72; |
| 326 |
|
| 327 |
vardef magstep primary m = mexp(46.67432m) enddef; |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
%% macros for drawing and filling |
| 332 |
|
| 333 |
def drawoptions(text t) = |
| 334 |
def _op_ = t enddef |
| 335 |
enddef; |
| 336 |
|
| 337 |
linejoin:=rounded; % parameters that effect drawing |
| 338 |
linecap:=rounded; |
| 339 |
miterlimit:=10; |
| 340 |
|
| 341 |
drawoptions(); |
| 342 |
|
| 343 |
pen currentpen; |
| 344 |
picture currentpicture; |
| 345 |
|
| 346 |
def fill expr c = addto currentpicture contour c _op_ enddef; |
| 347 |
def draw expr p = |
| 348 |
addto currentpicture |
| 349 |
if picture p: |
| 350 |
also p |
| 351 |
else: |
| 352 |
doublepath p withpen currentpen |
| 353 |
fi |
| 354 |
_op_ |
| 355 |
enddef; |
| 356 |
def filldraw expr c = |
| 357 |
addto currentpicture contour c withpen currentpen |
| 358 |
_op_ enddef; |
| 359 |
def drawdot expr p = |
| 360 |
if pair p : |
| 361 |
addto currentpicture doublepath p withpen currentpen _op_ |
| 362 |
else : |
| 363 |
errmessage("drawdot only accepts a pair expression") |
| 364 |
fi |
| 365 |
enddef; |
| 366 |
|
| 367 |
def unfill expr c = fill c withcolor background enddef; |
| 368 |
def undraw expr p = draw p withcolor background enddef; |
| 369 |
def unfilldraw expr c = filldraw c withcolor background enddef; |
| 370 |
def undrawdot expr z = drawdot z withcolor background enddef; |
| 371 |
def erase text t = |
| 372 |
def _e_ = withcolor background hide(def _e_=enddef;) enddef; |
| 373 |
t _e_ |
| 374 |
enddef; |
| 375 |
def _e_= enddef; |
| 376 |
|
| 377 |
def cutdraw text t = |
| 378 |
begingroup interim linecap:=butt; draw t _e_; endgroup enddef; |
| 379 |
|
| 380 |
vardef image(text t) = |
| 381 |
save currentpicture; |
| 382 |
picture currentpicture; |
| 383 |
currentpicture := nullpicture; |
| 384 |
t; |
| 385 |
currentpicture |
| 386 |
enddef; |
| 387 |
|
| 388 |
def pickup secondary q = |
| 389 |
if numeric q: numeric_pickup_ else: pen_pickup_ fi q enddef; |
| 390 |
def numeric_pickup_ primary q = |
| 391 |
if unknown pen_[q]: errmessage "Unknown pen"; clearpen |
| 392 |
else: currentpen:=pen_[q]; |
| 393 |
pen_lft:=pen_lft_[q]; |
| 394 |
pen_rt:=pen_rt_[q]; |
| 395 |
pen_top:=pen_top_[q]; |
| 396 |
pen_bot:=pen_bot_[q]; |
| 397 |
currentpen_path:=pen_path_[q] fi; enddef; |
| 398 |
def pen_pickup_ primary q = |
| 399 |
currentpen:=q; |
| 400 |
pen_lft:=xpart penoffset down of currentpen; |
| 401 |
pen_rt:=xpart penoffset up of currentpen; |
| 402 |
pen_top:=ypart penoffset left of currentpen; |
| 403 |
pen_bot:=ypart penoffset right of currentpen; |
| 404 |
path currentpen_path; enddef; |
| 405 |
newinternal pen_lft,pen_rt,pen_top,pen_bot,pen_count_; |
| 406 |
|
| 407 |
vardef savepen = pen_[incr pen_count_]=currentpen; |
| 408 |
pen_lft_[pen_count_]=pen_lft; |
| 409 |
pen_rt_[pen_count_]=pen_rt; |
| 410 |
pen_top_[pen_count_]=pen_top; |
| 411 |
pen_bot_[pen_count_]=pen_bot; |
| 412 |
pen_path_[pen_count_]=currentpen_path; |
| 413 |
pen_count_ enddef; |
| 414 |
|
| 415 |
def clearpen = currentpen:=nullpen; |
| 416 |
pen_lft:=pen_rt:=pen_top:=pen_bot:=0; |
| 417 |
path currentpen_path; |
| 418 |
enddef; |
| 419 |
def clear_pen_memory = |
| 420 |
pen_count_:=0; |
| 421 |
numeric pen_lft_[],pen_rt_[],pen_top_[],pen_bot_[]; |
| 422 |
pen currentpen,pen_[]; |
| 423 |
path currentpen_path, pen_path_[]; |
| 424 |
enddef; |
| 425 |
|
| 426 |
vardef lft primary x = x + if pair x: (pen_lft,0) else: pen_lft fi enddef; |
| 427 |
vardef rt primary x = x + if pair x: (pen_rt,0) else: pen_rt fi enddef; |
| 428 |
vardef top primary y = y + if pair y: (0,pen_top) else: pen_top fi enddef; |
| 429 |
vardef bot primary y = y + if pair y: (0,pen_bot) else: pen_bot fi enddef; |
| 430 |
|
| 431 |
vardef penpos@#(expr b,d) = |
| 432 |
(x@#r-x@#l,y@#r-y@#l)=(b,0) rotated d; |
| 433 |
x@#=.5(x@#l+x@#r); y@#=.5(y@#l+y@#r) enddef; |
| 434 |
|
| 435 |
def penstroke text t = |
| 436 |
forsuffixes e = l,r: path_.e:=t; endfor |
| 437 |
fill path_.l -- reverse path_.r -- cycle enddef; |
| 438 |
path path_.l,path_.r; |
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
%% High level drawing commands |
| 443 |
|
| 444 |
newinternal ahlength, ahangle; |
| 445 |
ahlength := 4; % default arrowhead length 4bp |
| 446 |
ahangle := 45; % default head angle 45 degrees |
| 447 |
|
| 448 |
vardef arrowhead expr p = |
| 449 |
save q,e; path q; pair e; |
| 450 |
e = point length p of p; |
| 451 |
q = gobble(p shifted -e cutafter makepath(pencircle scaled 2ahlength)) |
| 452 |
cuttings; |
| 453 |
(q rotated .5ahangle & reverse q rotated -.5ahangle -- cycle) shifted e |
| 454 |
enddef; |
| 455 |
|
| 456 |
path _apth; |
| 457 |
def drawarrow expr p = _apth:=p; _finarr enddef; |
| 458 |
def drawdblarrow expr p = _apth:=p; _findarr enddef; |
| 459 |
|
| 460 |
def _finarr text t = |
| 461 |
draw _apth t; |
| 462 |
filldraw arrowhead _apth t |
| 463 |
enddef; |
| 464 |
|
| 465 |
def _findarr text t = |
| 466 |
draw _apth t; |
| 467 |
filldraw arrowhead _apth withpen currentpen t; |
| 468 |
filldraw arrowhead reverse _apth withpen currentpen t |
| 469 |
enddef; |
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
%% macros for labels |
| 474 |
|
| 475 |
newinternal bboxmargin; bboxmargin:=2bp; |
| 476 |
|
| 477 |
vardef bbox primary p = |
| 478 |
llcorner p-(bboxmargin,bboxmargin) -- lrcorner p+(bboxmargin,-bboxmargin) |
| 479 |
-- urcorner p+(bboxmargin,bboxmargin) -- ulcorner p+(-bboxmargin,bboxmargin) |
| 480 |
-- cycle |
| 481 |
enddef; |
| 482 |
|
| 483 |
string defaultfont; |
| 484 |
newinternal defaultscale, labeloffset; |
| 485 |
defaultfont = "cmr10"; |
| 486 |
defaultscale := 1; |
| 487 |
labeloffset := 3bp; |
| 488 |
|
| 489 |
vardef thelabel@#(expr s,z) = % Position s near z |
| 490 |
save p; picture p; |
| 491 |
if picture s: p=s |
| 492 |
else: p = s infont defaultfont scaled defaultscale |
| 493 |
fi; |
| 494 |
p shifted (z + labeloffset*laboff@# - |
| 495 |
(labxf@#*lrcorner p + labyf@#*ulcorner p |
| 496 |
+ (1-labxf@#-labyf@#)*llcorner p |
| 497 |
) |
| 498 |
) |
| 499 |
enddef; |
| 500 |
|
| 501 |
def label = draw thelabel enddef; |
| 502 |
newinternal dotlabeldiam; dotlabeldiam:=3bp; |
| 503 |
vardef dotlabel@#(expr s,z) text t_ = |
| 504 |
label@#(s,z) t_; |
| 505 |
interim linecap:=rounded; |
| 506 |
draw z withpen pencircle scaled dotlabeldiam t_; |
| 507 |
enddef; |
| 508 |
def makelabel = dotlabel enddef; |
| 509 |
|
| 510 |
pair laboff, laboff.lft, laboff.rt, laboff.top, laboff.bot; |
| 511 |
pair laboff.ulft, laboff.llft, laboff.urt, laboff.lrt; |
| 512 |
laboff =(0,0); labxf =.5; labyf =.5; |
| 513 |
laboff.lft=(-1,0); labxf.lft=1; labyf.lft=.5; |
| 514 |
laboff.rt =(1,0); labxf.rt =0; labyf.rt =.5; |
| 515 |
laboff.bot=(0,-1); labxf.bot=.5; labyf.bot=1; |
| 516 |
laboff.top=(0,1); labxf.top=.5; labyf.top=0; |
| 517 |
laboff.ulft=(-.7,.7);labxf.ulft=1; labyf.ulft=0; |
| 518 |
laboff.urt=(.7,.7); labxf.urt=0; labyf.urt=0; |
| 519 |
laboff.llft=-(.7,.7);labxf.llft=1; labyf.llft=1; |
| 520 |
laboff.lrt=(.7,-.7); labxf.lrt=0; labyf.lrt=1; |
| 521 |
|
| 522 |
vardef labels@#(text t) = |
| 523 |
forsuffixes $=t: |
| 524 |
label@#(str$,z$); endfor |
| 525 |
enddef; |
| 526 |
vardef dotlabels@#(text t) = |
| 527 |
forsuffixes $=t: |
| 528 |
dotlabel@#(str$,z$); endfor |
| 529 |
enddef; |
| 530 |
vardef penlabels@#(text t) = |
| 531 |
forsuffixes $$=l,,r: forsuffixes $=t: |
| 532 |
makelabel@#(str$.$$,z$.$$); endfor endfor |
| 533 |
enddef; |
| 534 |
|
| 535 |
|
| 536 |
def range expr x = numtok[x] enddef; |
| 537 |
def numtok suffix x=x enddef; |
| 538 |
tertiarydef m thru n = |
| 539 |
m for x=m+1 step 1 until n: , numtok[x] endfor enddef; |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
%% Overall adminstration |
| 544 |
|
| 545 |
string extra_beginfig, extra_endfig; |
| 546 |
extra_beginfig = extra_endfig = ""; |
| 547 |
|
| 548 |
def beginfig(expr c) = |
| 549 |
begingroup |
| 550 |
charcode:=c; |
| 551 |
clearxy; clearit; clearpen; |
| 552 |
pickup defaultpen; |
| 553 |
drawoptions(); |
| 554 |
scantokens extra_beginfig; |
| 555 |
enddef; |
| 556 |
|
| 557 |
def endfig = |
| 558 |
scantokens extra_endfig; |
| 559 |
shipit; |
| 560 |
endgroup |
| 561 |
enddef; |
| 562 |
|
| 563 |
|
| 564 |
%% last-minute items |
| 565 |
|
| 566 |
vardef z@#=(x@#,y@#) enddef; |
| 567 |
|
| 568 |
def clearxy = save x,y enddef; |
| 569 |
def clearit = currentpicture:=nullpicture enddef; |
| 570 |
def shipit = shipout currentpicture enddef; |
| 571 |
|
| 572 |
let bye = end; outer end,bye; |
| 573 |
|
| 574 |
clear_pen_memory; % initialize the `savepen' mechanism |
| 575 |
clearit; |
| 576 |
|
| 577 |
newinternal defaultpen; |
| 578 |
pickup pencircle scaled .5bp; % set default line width |
| 579 |
defaultpen := savepen; |