MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
198 The definition of peepholed is rather dirty and using peepholed is restricted to well defined situations (like here). It's called a primary because it acts as an operator at the same level as * and scaled. urellipse ulellipse llellipse lrellipse ellipse negellipse tellipse bellipse lellipse rellipse urtriangle ultriangle lltriangle lrtriangle diamond negdiamond 8.4 Including graphics Figure 8.8 A collection of predefined clipping paths. This document demonstrates that it is no big problem to include METAPOST graphics in a TEX document. But how about including graphics in a METAPOST picture? In this section we will explore a couple of macros that provide you this feature. Before we go into details, we introduce a very impressive program called PSTOEDIT by Wolfgang Glunz. This program runs on top of GHOSTSCRIPT and is able to convert POSTSCRIPT code into other formats, among them METAPOST (that part of the PSTOEDIT code is due to Scott Pakin). Some of the graphics that we use in this section are produced that way. For us, the next call works well, but the exact call may differ per version or platform. pstoedit -ssp -dt -f mpost yourfile.ps newfile.mp We have converted the Dutch cow that shows up in many CONTEXT documents into METAPOST using this program. The resulting METAPOST file encapsulates the cow in METAPOST figure 1: beginfig(1). Of course you can process this file like any other, but more interesting is to use this code in an indirect way. loadfigure "mycow.mp" number 1 scaled .5 ; This call will load figure 1 from the specified METAPOST file, in such a way that there is no interference with the current (encapsulating) figure. Special effects Including graphics
Because this graphic is the result from a conversion, there are only paths. If you want to import a more complex graphic, you need to make sure that the variables used in there do not conflict with the one currently in use. METAPOST is good in drawing vector graphics, but lacks natural support for bitmaps, but the next macro offers a way out. This macro permits you to include graphics in PNG, PDF, and JPG format, or more precise: those formats supported by PDFTEX. externalfigure "hacker.png" scaled 5cm shifted (-6cm,0) ; externalfigure "hacker.png" scaled 5cm slanted .5 ; You can apply the usual transformations, but only those applied directly will be taken into account. This means that you (currently) cannot store external figures in picture variables in order to transform them afterwards. Although you are limited in what you can do with such graphics, you can include them multiple times with a minimum of overhead. Graphics are stored in objects and embedded only once. numeric s ; pair d, c ; for i := 1 upto 5 : s := 3cm randomized 1cm ; % size of picture c := .5(s,s) ; % center of picture d := (2cm*i,.5cm) randomized .5cm ; % displacement externalfigure "hacker.png" scaled s rotatedaround (c,0 randomized 30) shifted d ; endfor ; Because we cannot store the graphic in a picture and scale afterwards, we calculate the scale in advance, so that we can rotate around the center. Including graphics Special effects 199
- Page 151 and 152: pab := pab cutafter (pab intersecti
- Page 153 and 154: fill p withcolor \MPcolor{lightgray
- Page 155 and 156: The previous example also demonstra
- Page 157 and 158: \setMPlayer [test] [somepos-1] [loc
- Page 159 and 160: 6 Page backgrounds Especially in in
- Page 161 and 162: As soon as you want to make an elec
- Page 163 and 164: do_it (1,4,false) ; do_it (5,4,fals
- Page 165 and 166: gigigi Watch how the bounding boxes
- Page 167 and 168: You can test this concept yourself
- Page 169 and 170: StartPage ; fill Area[Text][Text] s
- Page 171 and 172: fi ; Main := Main enlarged 6pt ; pi
- Page 173 and 174: ulcorner Field[Text] [Text] -urcorn
- Page 175 and 176: The left picture demonstrates what
- Page 177 and 178: There are two more operators: inner
- Page 179 and 180: 7 Shapes, symbols and buttons One c
- Page 181 and 182: Table 7.1 demonstrates how scratch
- Page 183 and 184: for i := 1 upto \MPvar{n} : xpos :=
- Page 185 and 186: This table is defined as: \bTABLE[f
- Page 187 and 188: Since we have collected some nice b
- Page 189 and 190: 8 Special effects Sometimes we want
- Page 191 and 192: Because of this implementation, sha
- Page 193 and 194: test_shade(origin shifted (.25cm,0)
- Page 195 and 196: fill p shifted (3cm,0) withcolor .5
- Page 197 and 198: \definecolor [tred] [r=1,t=.5,a=exc
- Page 199 and 200: Figure 8.4 Another clipped cow. \pl
- Page 201: withpen pencircle scaled 4mm withco
- Page 205 and 206: The resulting PDF file can be inclu
- Page 207 and 208: Including another METAPOST graphic,
- Page 209 and 210: After these examples your are proba
- Page 211 and 212: In this graphic, we have two text f
- Page 213 and 214: } {}} Here we feed some MATHML int
- Page 215 and 216: 9 Functions METAPOST provides a wid
- Page 217 and 218: 9.2 Grids Some day you may want to
- Page 219 and 220: 13 13 13 13 Figure 9.1 Quick and di
- Page 221 and 222: 2 − ×10 1 − 1 0×100 Figure 9.
- Page 223 and 224: Figure 9.3 By using transparent col
- Page 225 and 226: There are enough applications out t
- Page 227 and 228: Of course we could extend this LUA
- Page 229 and 230: 10 Typesetting in METAPOST It is sa
- 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
Because this graphic is the result from a conversion, there are only paths. If you want to import a<br />
more complex graphic, you need to make sure that the variables used in there do not conflict with<br />
the one currently in use.<br />
METAPOST is good in drawing vector graphics, but lacks natural support for bitmaps, but the next<br />
macro offers a way out. This macro permits you to include graphics in PNG, PDF, and JPG format,<br />
or more precise: those formats supported by PDFTEX.<br />
externalfigure "hacker.png" scaled 5cm shifted (-6cm,0) ;<br />
externalfigure "hacker.png" scaled 5cm slanted .5 ;<br />
You can apply the usual transformations, but only those applied directly will be taken into account.<br />
This means that you (currently) cannot store external figures in picture variables in order<br />
to transform them afterwards.<br />
Although you are limited in what you can do with such graphics, you can include them multiple<br />
times with a minimum of overhead. Graphics are stored in objects and embedded only once.<br />
numeric s ; pair d, c ;<br />
for i := 1 upto 5 :<br />
s := 3cm randomized 1cm ; % size of picture<br />
c := .5(s,s) ; % center of picture<br />
d := (2cm*i,.5cm) randomized .5cm ; % displacement<br />
externalfigure "hacker.png"<br />
scaled s rotatedaround (c,0 randomized 30) shifted d ;<br />
endfor ;<br />
Because we cannot store the graphic in a picture and scale afterwards, we calculate the scale in<br />
advance, so that we can rotate around the center.<br />
Including graphics Special effects<br />
199