29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

296<br />

addto currentpicture also q shifted (0,radius/2) ;<br />

\stopuseMPgraphic<br />

13.6 Growing graphics<br />

Although METAPOST is not really suited as a simulation engine, it is possible to build graphics that<br />

are built and displayed incrementally with a sequence of mouse clicks. The following example is<br />

the result of an email discussion David Arnold and the author had while METAFUN evolved.<br />

Instead of defining the graphics in a separate METAPOST file, we will incorporate them in the document<br />

source in which they are used. We can use several methods.<br />

1. Define macros and figures in a separate file and include the graphics as external graphics.<br />

2. Define everything in the document source as usable graphics and include the graphics using<br />

\useMPgraphic.<br />

3. Package the graphic components in buffers and paste those together as graphics that can be<br />

processed at run time.<br />

The first method is the most independent one, which has its advantages if we want to use the<br />

graphics in other applications too. The second method works well in graphics where parts of the<br />

definitions change between invocations of the graphic. This method follows the template:<br />

\startuseMPgraphic{whatever}<br />

...<br />

\stopuseMPgraphic<br />

\startuseMPgraphic{result}<br />

...<br />

\includeMPgraphic{whatever}<br />

...<br />

\stopuseMPgraphic<br />

\useMPgraphic{result}<br />

The disadvantage of this method is that it cannot be combined with btex--etex since it is nearly impossible<br />

to determine when, how, and to what extent the content of a graphic should be expanded<br />

before writing it to the temporary METAPOST file.<br />

Therefore, we will demonstrate how buffers can be used. This third method closely parallels the<br />

first way of defining graphics. A nice side effect is that we can easily typeset these buffers verbatim,<br />

which we did to typeset this document.<br />

We are going to do a classic compass and straightedge construction, the bisection of a line segment<br />

joining two arbitrary points. We will construct five graphics, where each one displays one step of<br />

the construction. We will embed each graphic in a start--stop command. Later we will see the<br />

advantage of this strategy.<br />

A few applications Growing graphics

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

Saved successfully!

Ooh no, something went wrong!