MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
278 p := fullcircle scaled (2*length(loc-ori)) shifted ori ; q := freesquare xyscaled (urcorner s - llcorner s) ; l := point (xpart (p intersectiontimes (ori--loc))) of q ; draw q shifted loc withpen pencircle scaled .5pt ; draw l shifted loc withcolor .625yellow ; draw loc withcolor .625red ; s enddef ; The macro xyscaled is part of METAFUN and scales in two directions at once. The METAPOST primitive intersectiontimes returns a pair of time values of the point where two paths intersect. The first part of the pair concerns the first path. text text text text text text text text text text text textextext text text We are now a small step from the exact placement. If we change the last line of the macro into: (s shifted -l) we get the displacement we want. Although the final look and feel is also determined by the text itself, the average result is quite acceptable. text text text text text text text text text text text text texttext text text Because we also want to pass pictures, and add a bit of offset too, the final implementation is slightly more complicated. The picture is handled with an additional condition, and the offset with the METAFUN macro enlarged. newinternal freelabeloffset ; freelabeloffset := 3pt ; vardef thefreelabel (expr str, loc, ori) = save s, p, q, l ; picture s ; path p, q ; pair l ; interim labeloffset := freelabeloffset ; s := if string str : thelabel(str,loc) else : str shifted -center str shifted loc fi ; setbounds s to boundingbox s enlarged freelabeloffset ; A few applications Free labels
p := fullcircle scaled (2*length(loc-ori)) shifted ori ; q := freesquare xyscaled (urcorner s - llcorner s) ; l := point (xpart (p intersectiontimes (ori--loc))) of q ; setbounds s to boundingbox s enlarged -freelabeloffset ; (s shifted -l) enddef ; Watch how we temporarily enlarge the bounding box of the typeset label text. We will now test this macro on a slightly rotated circle, using labels typeset by TEX. The reverse is there purely for cosmetic reasons, to suit the label texts. defining in funny macros. and on go on Can't we? We can pickup pencircle scaled 1mm ; path p ; p := reverse fullcircle rotated -25 scaled 3cm ; draw p withcolor .625yellow ; pair cp ; cp := center p ; freedotlabel (btex \strut We can etex, point 0 of p, cp) ; freedotlabel (btex \strut go on etex, point 1 of p, cp) ; freedotlabel (btex \strut and on etex, point 2 of p, cp) ; freedotlabel (btex \strut in etex, point 3 of p, cp) ; freedotlabel (btex \strut defining etex, point 4 of p, cp) ; freedotlabel (btex \strut funny etex, point 5 of p, cp) ; freedotlabel (btex \strut macros. etex, point 6 of p, cp) ; freedotlabel (btex \strut Can't we? etex, point 7 of p, cp) ; Unfortunately we can run into problems due to rounding errors. Therefore we use a less readable but more safe expression for calculating the intersection points. Instead of using point loc as endpoint we use loc shifted over a very small distance into the direction loc from ori. In the assignment to l we replace loc by: ( (1+eps) * arclength(ori--loc) * unitvector(loc-ori) ) 13.3 Marking angles A convenient METAPOST macro is unitvector. When we draw a line segment from the origin to the point returned by this macro, the segment has a length of 1 base point. This macro has a wide range of applications, but some basic knowlegde of vector algebra is handy. The following lines of METAPOST code demonstrate the basics behind unitvectors. Marking angles A few applications 279
- Page 231 and 232: Meta is a female lion! Figure 10.2
- Page 233 and 234: We use the low level CONTEXT macro
- Page 235 and 236: So, now we have: M etaPostisFun! Wh
- Page 237 and 238: n := n + 1 ; len[n] := \the\wd\MPbo
- Page 239 and 240: ap := point at of RotPath ; ad := d
- Page 241 and 242: \startoverlay {\startuseMPgraphic{f
- Page 243 and 244: \startuseMPgraphic{text draw} draw
- Page 245 and 246: vsize := ypart urcorner p - ypart l
- Page 247 and 248: We are now ready for an attempt to
- Page 249 and 250: We can manipulate the heigth and de
- Page 251 and 252: \strutheight) ; % height of first l
- Page 253 and 254: w := h := 6cm ; o := 6pt ; path p ;
- Page 255 and 256: Donald Knuth has spent the past sev
- Page 257 and 258: Donald Knuth has spent the past sev
- Page 259 and 260: 11 Debugging Those familiar with CO
- Page 261 and 262: 4 3 5 2 6 1 0 7 8 You can pass opti
- Page 263 and 264: 3 4 0 2 1 Of course you may want to
- Page 265 and 266: 12 Defining styles Since the integr
- Page 267 and 268: color=gray, contrastcolor=gray, sty
- Page 269 and 270: def right_menu_button (expr nn, rr,
- Page 271 and 272: \Topic {Edward R. Tufte} \input tuf
- Page 273 and 274: A Few Nice Quotes A Simple Style De
- Page 275 and 276: 13 A few applications For those who
- Page 277 and 278: vardef spring (expr a, b, w, h, n)
- Page 279 and 280: There is a numeric constant labelof
- Page 281: text text text text text text text
- Page 285 and 286: These definitions of anglebetween a
- Page 287 and 288: Because in most cases we want the l
- Page 289 and 290: γ δ β ɛ α ζ δ γ β ɛ metho
- Page 291 and 292: There are for sure more (efficient)
- Page 293 and 294: The next circle that we draw shows
- Page 295 and 296: popcurrentpicture ; enddef ; Here,
- Page 297 and 298: draw (u,i) -- (2u,i) withcolor .5wh
- Page 299 and 300: Figure 13.4 Koffka's examples of ma
- Page 301 and 302: \startbuffer[a] def start_everythin
- Page 303 and 304: pointC := circleA intersectionpoint
- Page 305 and 306: draw_basics ; draw_circles ; draw_i
- Page 307 and 308: Figure 13.6 Bisecting a line segmen
- Page 309 and 310: z1 = (0, height/2) ; z2 = (width/2-
- Page 311 and 312: The clipping path is applied by say
- Page 313 and 314: 13.8 Music sheets The next example
- Page 315 and 316: The euro symbol A few applications
- Page 317 and 318: draw i withpen pencircle scaled 1pt
- Page 319 and 320: 16 draw b withpen pencircle scaled
- Page 321 and 322: \startMPcode \includeMPgraphic{gamb
- Page 323 and 324: 14 METAFUN macros CONTEXT comes wit
- Page 325 and 326: A METAPOST syntax In the METAFONT b
- Page 327 and 328: 〈number or fraction〉 → 〈num
- Page 329 and 330: 〈suffix〉 → 〈empty〉 | 〈s
- Page 331 and 332: 〈assignment〉 → 〈variable〉
278<br />
p := fullcircle scaled (2*length(loc-ori)) shifted ori ;<br />
q := freesquare xyscaled (urcorner s - llcorner s) ;<br />
l := point (xpart (p intersectiontimes (ori--loc))) of q ;<br />
draw q shifted loc withpen pencircle scaled .5pt ;<br />
draw l shifted loc withcolor .625yellow ;<br />
draw loc withcolor .625red ;<br />
s<br />
enddef ;<br />
The macro xyscaled is part of METAFUN and scales in two directions at once. The METAPOST primitive<br />
intersectiontimes returns a pair of time values of the point where two paths intersect. The<br />
first part of the pair concerns the first path.<br />
text text text<br />
text text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
textextext text<br />
text<br />
We are now a small step from the exact placement. If we change the last line of the macro into:<br />
(s shifted -l)<br />
we get the displacement we want. Although the final look and feel is also determined by the text<br />
itself, the average result is quite acceptable.<br />
text text text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text<br />
text texttext text text<br />
Because we also want to pass pictures, and add a bit of offset too, the final implementation is<br />
slightly more complicated. The picture is handled with an additional condition, and the offset<br />
with the METAFUN macro enlarged.<br />
newinternal freelabeloffset ; freelabeloffset := 3pt ;<br />
vardef thefreelabel (expr str, loc, ori) =<br />
save s, p, q, l ; picture s ; path p, q ; pair l ;<br />
interim labeloffset := freelabeloffset ;<br />
s := if string str : thelabel(str,loc)<br />
else : str shifted -center str shifted loc fi ;<br />
setbounds s to boundingbox s enlarged freelabeloffset ;<br />
A few applications Free labels