29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The second line does just as it says: it draws a rectangle of certain dimensions in a certain color.<br />

In the third line we draw a colored dot at the origin of the coordinate system in which we are<br />

drawing. Finally, we set up a smaller pen and draw the bounding box of the current picture, using<br />

the variable currentpicture. Normally, all drawn shapes end up in this picture variable.<br />

2.2 Bounding boxes<br />

If you take a close look at the last picture in the previous section, you will notice that the bounding<br />

box is larger than the picture. This is one of the nasty side effects of METAPOST's bbox macro. This<br />

macro draws a box, but with a certain offset. The next example shows how we can manipulate<br />

this offset. Remember that in order to process the next examples, you should embed the code in<br />

beginfig and endfig macros. Also, in stand--alone graphics, don't forget to say \input mp-tool<br />

first.<br />

pickup pencircle scaled .5cm ;<br />

draw unitsquare xscaled 8cm yscaled 1cm withcolor .625white ;<br />

path bb ; bboxmargin := 0pt ; bb := bbox currentpicture ;<br />

draw bb withpen pencircle scaled 1pt withcolor .625red ;<br />

draw origin withpen pencircle scaled 5pt withcolor .625yellow ;<br />

In the third line we define a path variable. We assign the current bounding box to this variable,<br />

but first we set the offset to zero. The last line demonstrates how to draw such a path. Instead of<br />

setting the pen as we did in the first line, we pass the dimensions directly.<br />

Where draw draws a path, the fill macro fills one. In order to be filled, a path should be closed,<br />

which is accomplished by the cycle primitive, as we saw in constructing the unitsquare path.<br />

pickup pencircle scaled .5cm ;<br />

fill unitsquare xscaled 8cm yscaled 1cm withcolor .625white ;<br />

path bb ; bboxmargin := 0pt ; bb := bbox currentpicture ;<br />

draw bb withpen pencircle scaled 1pt withcolor .625red ;<br />

draw origin withpen pencircle scaled 5pt withcolor .625yellow ;<br />

This example demonstrates that when we fill the path, the resulting graphic is smaller. Where<br />

draw follows the center of a path, fill stays inside the path.<br />

A third alternative is the filldraw macro. From the previous examples, we would expect a bounding<br />

box that matches the one of the drawn path.<br />

Bounding boxes A few more details<br />

67

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!