MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
308 The complete logo definition is a bit more extensive because we also want to add a background. Because we need to clip the blue foreground graphic, we must temporarily store it when we fill the background. numeric width, height, line, delta ; width = 5cm ; height = width/2 ; line = height/4 ; delta = line ; linejoin := mitered ; pickup pencircle scaled line ; color nsblue ; nsblue := (0,0,1) ; color nsyellow ; nsyellow := (1,1,0) ; z1 = (0, height/2) ; z2 = (width/2-height/4, y1) ; z3 = (width/2+height/4, y4) ; z4 = (width, 0) ; z5 = (x4+height/2, y1) ; z6 = (x4, 2y1) ; z7 = 1.5[z5,z6] ; path p ; p := z1--z2--z3--z4 ; path q ; q := z3--z4--z5--z7 ; numeric d, lx, ly, ux, uy ; d = line/2 ; lx = -3d - d/3 ; ly = -d ; ux = rt x5 + d/3 ; uy = top y6 ; path r ; r := (lx,ly)--(ux,ly)--(ux,uy)--(lx,uy)--cycle; lx := lx-delta ; ly := ly-delta ; ux := ux+delta ; uy := uy+delta ; path s ; s := (lx,ly)--(ux,ly)--(ux,uy)--(lx,uy)--cycle; draw p withcolor nsblue ; draw q withcolor nsblue ; addto currentpicture also currentpicture rotatedaround (.5[z2,z3],180) shifted (height/4,height/2) ; picture savedpicture ; savedpicture := currentpicture ; clip currentpicture to r ; setbounds currentpicture to r ; savedpicture := currentpicture ; currentpicture := nullpicture ; fill s withcolor nsyellow ; addto currentpicture also savedpicture ; For practical use it makes sense to package this definition in a macro to which we pass the dimensions. A few applications Simple Logos
13.8 Music sheets The next example demonstrates quite some features. Imagine that we want to make us a couple of sheets so that we can write a musical masterpiece. Let's also forget that TEX can draw lines, which means that somehow we need to use METAPOST. Drawing a bar is not that complicated as the following code demonstrates. \startusableMPgraphic{bar} vardef MusicBar (expr width, gap, linewidth, barwidth) = image ( interim linecap := butt ; for i=1 upto 5 : draw ((0,0)--(width,0)) shifted (0,(i-1)*gap) withpen pencircle scaled linewidth ; endfor ; for i=llcorner currentpicture -- ulcorner currentpicture , lrcorner currentpicture -- urcorner currentpicture : draw i withpen pencircle scaled barwidth ; endfor ; ) enddef ; \stopusableMPgraphic We can define the sidebars a bit more efficient using two predefined subpaths: for i=leftboundary currentpicture, rightboundary currentpicture : We define a macro MusicBar that takes four arguments. The first two determine the dimensions, the last two concern the line widths. Now watch how we can use this macro: \includeMPgraphic{bar} ; draw MusicBar (200pt, 6pt, 1pt, 2pt) ; draw MusicBar (300pt, 6pt, 1pt, 2pt) shifted (0,-30pt) ; As you can see in this example, the bar is a picture that can be transformed (shifted in our case). However, a close look at the macro teaches us that it does a couple of draws too. This is possible because we wrap the whole in an image using the image macro. This macro temporary saves the current picture, and at the end puts the old currentpicture under the new one. We wrap the whole in a vardef. This means that the image is returned as if it was a variable. Actually, the last thing in a vardef should be a proper return value, in our case a picture. This also means that we may not end the vardef with a semi colon. So, when the content of the vardef is expanded, we get something draw some_picture ... ; Music sheets A few applications 309
- 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 and 282: text text text text text text text
- Page 283 and 284: p := fullcircle scaled (2*length(lo
- 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: The clipping path is applied by say
- 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〉
- Page 333 and 334: 〈command〉 → clip 〈picture v
- Page 335 and 336: 〈if test〉 → if 〈boolean exp
- Page 337 and 338: B This document This document is pr
- Page 339 and 340: C Reference C.1 Paths In this chapt
- Page 341 and 342: tension atleast numeric (0,0)..(.75
- Page 343 and 344: angle origin--dir(angle(1,1)) metap
- Page 345 and 346: circle bcircle metafun variable lci
- Page 347 and 348: path randomized numeric/pair unitsq
- Page 349 and 350: path stretched numeric/pair (fullci
- Page 351 and 352: path zscaled pair fullcircle zscale
- Page 353 and 354: path llenlarged numeric fullcircle
- Page 355 and 356: path urmoved numeric fullcircle urm
- Page 357 and 358: everse path reverse fullcircle shif
- Page 359 and 360: oundingbox path boundingbox fullcir
- Page 361 and 362: C.3 Points top pair top center full
308<br />
The complete logo definition is a bit more extensive because we also want to add a background.<br />
Because we need to clip the blue foreground graphic, we must temporarily store it when we fill<br />
the background.<br />
numeric width, height, line, delta ;<br />
width = 5cm ; height = width/2 ; line = height/4 ; delta = line ;<br />
linejoin := mitered ; pickup pencircle scaled line ;<br />
color nsblue ; nsblue := (0,0,1) ;<br />
color nsyellow ; nsyellow := (1,1,0) ;<br />
z1 = (0, height/2) ;<br />
z2 = (width/2-height/4, y1) ;<br />
z3 = (width/2+height/4, y4) ;<br />
z4 = (width, 0) ;<br />
z5 = (x4+height/2, y1) ;<br />
z6 = (x4, 2y1) ;<br />
z7 = 1.5[z5,z6] ;<br />
path p ; p := z1--z2--z3--z4 ; path q ; q := z3--z4--z5--z7 ;<br />
numeric d, lx, ly, ux, uy ; d = line/2 ;<br />
lx = -3d - d/3 ; ly = -d ; ux = rt x5 + d/3 ; uy = top y6 ;<br />
path r ; r := (lx,ly)--(ux,ly)--(ux,uy)--(lx,uy)--cycle;<br />
lx := lx-delta ; ly := ly-delta ; ux := ux+delta ; uy := uy+delta ;<br />
path s ; s := (lx,ly)--(ux,ly)--(ux,uy)--(lx,uy)--cycle;<br />
draw p withcolor nsblue ; draw q withcolor nsblue ;<br />
addto currentpicture also currentpicture<br />
rotatedaround (.5[z2,z3],180) shifted (height/4,height/2) ;<br />
picture savedpicture ; savedpicture := currentpicture ;<br />
clip currentpicture to r ;<br />
setbounds currentpicture to r ;<br />
savedpicture := currentpicture ; currentpicture := nullpicture ;<br />
fill s withcolor nsyellow ;<br />
addto currentpicture also savedpicture ;<br />
For practical use it makes sense to package this definition in a macro to which we pass the dimensions.<br />
A few applications Simple Logos