MetaFun - Pragma ADE
MetaFun - Pragma ADE MetaFun - Pragma ADE
68 4 5 pickup pencircle scaled .5cm ; filldraw unitsquare xscaled 8cm yscaled 1cm withcolor .625white ; path bb ; bboxmargin := 0pt ; bb := bbox currentpicture ; draw bb withpen pencircle scaled 1pt withcolor .625red ; draw origin withpen pencircle scaled 5pt withcolor .625yellow ; The resulting graphic has the bounding box of the fill. Note how the path, because it is stroked with a .5cm pen, extends beyond the border of the previous bounding box. The way this image shows up depends on the viewer (settings) you use to render the graphic. For example, in GHOSTVIEW, if you disable clipping to the bounding box, only the positive quadrant of the graphic is shown. 4 From the previous examples, you can conclude that the following alternative results in a proper bounding box: pickup pencircle scaled .5cm ; path p ; p := unitsquare xscaled 8cm yscaled 1cm ; fill p withcolor .625white ; draw p withcolor .625white ; path bb ; bboxmargin := 0pt ; bb := bbox currentpicture ; draw bb withpen pencircle scaled 1pt withcolor .625red ; draw origin withpen pencircle scaled 5pt withcolor .625yellow ; The CONTEXT distribution comes with a set of METAPOST modules, one of which contains the drawfill macro, which provides the outer bounding box. 5 Next we demonstrate its use in another, more complicated example. picture finalpicture ; finalpicture := nullpicture ; numeric n ; n := 0 ; bboxmargin := 0pt ; pickup pencircle scaled .5cm ; def shape = unitsquare scaled 2cm withcolor .625white ; draw bbox currentpicture withpen pencircle scaled .5mm withcolor .625red ; addto finalpicture also currentpicture shifted(n*3cm,0) ; currentpicture := nullpicture ; n := n+1 ; enddef ; Old versions of METAPOST calculated the boundingbox differently for a filldraw: through the middle of the penpath. Starting from version 1.0 METAPOST calculates the boundingbox differently and the distinction between drawfill and filldraw is gone. We keep them around both for compatibility. A few more details Bounding boxes
fill shape ; draw shape ; filldraw shape ; drawfill shape ; currentpicture := finalpicture ; Here we introduce a macro definition, shape. In METAPOST, the start of a macro definition is indicated with the keyword def. Thereafter, you can insert other variables and commands, even other macro definitions. The keyword enddef signals the end of the macro definition. The result is shown in figure 2.1; watch the bounding boxes. Close reading of the macro will reveal that the fill, draw, filldraw and drawfill macros are applied to the first unitsquare path in the macro. Figure 2.1 A fill, draw, filldraw and drawfill applied to the same square. In this macro, bbox calls a macro that returns the enlarged bounding box of a path. By setting bboxmargin we can influence how much the bounding box is enlarged. Since this is an existing variable, we don't have to allocate it, like we do with numeric n. Unless you take special precautions, variables are global by nature and persistent outside macros. picture finalpicture ; finalpicture := nullpicture ; Just as numeric allocates an integer variable, the picture primitive allocates a picture data structure. We explicitly have to set this picture to nothing using the built--in primitive nullpicture. Later on, we will add the drawn paths as accumulated in currentpicture to this finalpicture in the following manner. addto finalpicture also currentpicture shifted(n*3cm,0) ; Since we want to add a few more and don't want them to overlap, we shift them. Therefore we have to erase the current picture as well as increment the shift counter. currentpicture := nullpicture ; n := n+1 ; The drawfill macro is one of the METAFUN macros. Another handy macro is boundingbox. When used instead of bbox, you don't have to set the margin to zero. Figure 2.2 The influence of pens on fill. Bounding boxes A few more details 69
- Page 21 and 22: 4 0 1 3 2 "z0..z1..z2..z3..z0" Only
- Page 23 and 24: 0 1 3 2 "z0..z1..z2--z3" Watch how
- Page 25 and 26: 0 1 0 2 2 1 "(z0..z1..z2..z3) cutaf
- Page 27 and 28: 2 0 1 Using ( ) is not mandatory bu
- Page 29 and 30: 0 4 1 3 2 0 These two graphics were
- Page 31 and 32: Since we don't consider this unfill
- Page 33 and 34: First there is the concept of varia
- Page 35 and 36: 1.8 Loops Yet another programming c
- Page 37 and 38: If in the definition of doublescale
- Page 39 and 40: test (a) (b) (c) (d) ; test (a,b) (
- Page 41 and 42: If you forget about the colors, the
- Page 43 and 44: linejoin=mitered linecap=butt linej
- Page 45 and 46: 1.15 Text Most dashpatterns can be
- Page 47 and 48: Z13 Z24 Z14 Z1 Z12 Z2 Z21 Z23 Z11 Z
- Page 49 and 50: 3 Because we want to call this macr
- Page 51 and 52: dotlabel.rt ("$Z_{3}$", z3) ; dotla
- Page 53 and 54: A different approach is to use a tw
- Page 55 and 56: The graphic extends beyond the boun
- Page 57 and 58: p := (p shifted (5cm,0)) randomized
- Page 59 and 60: path p ; p := (0,0) -- (2cm,3cm) ;
- Page 61 and 62: path p ; p := (0cm,0cm) -- (4cm,1cm
- Page 63 and 64: Here, the image macro creates an (a
- Page 65 and 66: So, in addition to on to specify a
- Page 67 and 68: Watch how we can pass a point (poin
- Page 69 and 70: 2 A few more details In this chapte
- Page 71: The second line does just as it say
- Page 75 and 76: 2.3 Units 6 As you can see here, as
- Page 77 and 78: 2.4 Scaling and shifting When we dr
- Page 79 and 80: Especially when a path results from
- Page 81 and 82: points first order curve second ord
- Page 83 and 84: first iteration second iteration th
- Page 85 and 86: and get: We don't even need that mu
- Page 87 and 88: Figure 2.3 Circles with minimized i
- Page 89 and 90: The tension specifier can be used t
- Page 91 and 92: The asymetrical tensions are less p
- Page 93 and 94: z0 .. z1 .. z2 z0 {curl 1} .. z1 ..
- Page 95 and 96: 7 In literature concerning POSTSCRI
- Page 97 and 98: currentpicture := currentpicture sl
- Page 99 and 100: We can achieve this by defining poi
- Page 101 and 102: We're still not there. Like in a pr
- Page 103 and 104: Due to the thicker line width used
- Page 105 and 106: left up down right The previous def
- Page 107 and 108: Here the & glues strings together,
- Page 109 and 110: picture p ; p := "MetaFun" normalin
- Page 111 and 112: pickup pencircle scaled 2pt ; draw
- Page 113 and 114: Because the z--variables are used f
- Page 115 and 116: 3 Embedded graphics In addition to
- Page 117 and 118: \startMPcode fill fullcircle scaled
- Page 119 and 120: \startuniqueMPgraphic{right or wron
- Page 121 and 122: {\externalfigure[mprun:extrafun::my
fill shape ; draw shape ; filldraw shape ; drawfill shape ;<br />
currentpicture := finalpicture ;<br />
Here we introduce a macro definition, shape. In METAPOST, the start of a macro definition is indicated<br />
with the keyword def. Thereafter, you can insert other variables and commands, even<br />
other macro definitions. The keyword enddef signals the end of the macro definition. The result<br />
is shown in figure 2.1; watch the bounding boxes. Close reading of the macro will reveal that the<br />
fill, draw, filldraw and drawfill macros are applied to the first unitsquare path in the macro.<br />
Figure 2.1 A fill, draw, filldraw and<br />
drawfill applied to the same square.<br />
In this macro, bbox calls a macro that returns the enlarged bounding box of a path. By setting<br />
bboxmargin we can influence how much the bounding box is enlarged. Since this is an existing<br />
variable, we don't have to allocate it, like we do with numeric n. Unless you take special precautions,<br />
variables are global by nature and persistent outside macros.<br />
picture finalpicture ; finalpicture := nullpicture ;<br />
Just as numeric allocates an integer variable, the picture primitive allocates a picture data structure.<br />
We explicitly have to set this picture to nothing using the built--in primitive nullpicture.<br />
Later on, we will add the drawn paths as accumulated in currentpicture to this finalpicture<br />
in the following manner.<br />
addto finalpicture also currentpicture shifted(n*3cm,0) ;<br />
Since we want to add a few more and don't want them to overlap, we shift them. Therefore we<br />
have to erase the current picture as well as increment the shift counter.<br />
currentpicture := nullpicture ; n := n+1 ;<br />
The drawfill macro is one of the METAFUN macros. Another handy macro is boundingbox. When<br />
used instead of bbox, you don't have to set the margin to zero.<br />
Figure 2.2 The influence of pens on fill.<br />
Bounding boxes A few more details<br />
69