MetaFun - Pragma ADE

MetaFun - Pragma ADE MetaFun - Pragma ADE

pragma.ade.com
from pragma.ade.com More from this publisher
29.11.2012 Views

270 Defining styles Adaptive buttons

13 A few applications For those who need to be inspired, we will demonstrate how METAPOST can be used to enhance your document with simple graphics. In these examples we will try to be not too clever, simply because we lack the experience to be that clever. The real tricks can be found in the files that come with METAPOST. 13.1 Simple drawings In the words of John Hobby, the creator of METAPOST, “METAPOST is particularly well--suited for generating figures for technical documents where some aspects of a picture may be controlled by mathematical or geometrical constraints that are best expressed symbolically. In other words, METAPOST is not meant to take the place of a freehand drawing tool or even an interactive graphics editor”. An example of such a picture is the following one, which is dedicated to David Arnold, who asked me once how to draw a spring. So, imagine that we want to draw a schematic view of a system of four springs. A rather natural way to define such a system is: z1 = (+2cm,0) ; z2 = (0,+2cm) ; z3 = (-2cm,0) ; z4 = (0,-2cm) ; pickup pencircle scaled 1.5pt ; drawoptions (withcolor .625red) ; draw spring (z1, z2, .75cm, 2, 10) ; draw z1 -- 1.5 z1 ; draw spring (z2, z3, .75cm, 2, 9) ; draw z2 -- 1.1 z2 ; draw spring (z3, z4, .75cm, 2, 8) ; draw z3 -- 1.5 z3 ; draw spring (z4, z1, .75cm, 2, 7) ; draw z4 -- 1.1 z4 ; Here, the macro spring takes 5 arguments: two points, the width of the winding, the length of the connecting pieces, and the number of elements (half windings). The definition of spring is less complicated than readable. Simple drawings A few applications 271

13 A few applications<br />

For those who need to be inspired, we will demonstrate how METAPOST can be used to enhance your document<br />

with simple graphics. In these examples we will try to be not too clever, simply because we lack the experience<br />

to be that clever. The real tricks can be found in the files that come with METAPOST.<br />

13.1 Simple drawings<br />

In the words of John Hobby, the creator of METAPOST, “METAPOST is particularly well--suited for<br />

generating figures for technical documents where some aspects of a picture may be controlled<br />

by mathematical or geometrical constraints that are best expressed symbolically. In other words,<br />

METAPOST is not meant to take the place of a freehand drawing tool or even an interactive graphics<br />

editor”.<br />

An example of such a picture is the following one, which is dedicated to David Arnold, who asked<br />

me once how to draw a spring. So, imagine that we want to draw a schematic view of a system of<br />

four springs.<br />

A rather natural way to define such a system is:<br />

z1 = (+2cm,0) ; z2 = (0,+2cm) ;<br />

z3 = (-2cm,0) ; z4 = (0,-2cm) ;<br />

pickup pencircle scaled 1.5pt ;<br />

drawoptions (withcolor .625red) ;<br />

draw spring (z1, z2, .75cm, 2, 10) ; draw z1 -- 1.5 z1 ;<br />

draw spring (z2, z3, .75cm, 2, 9) ; draw z2 -- 1.1 z2 ;<br />

draw spring (z3, z4, .75cm, 2, 8) ; draw z3 -- 1.5 z3 ;<br />

draw spring (z4, z1, .75cm, 2, 7) ; draw z4 -- 1.1 z4 ;<br />

Here, the macro spring takes 5 arguments: two points, the width of the winding, the length of<br />

the connecting pieces, and the number of elements (half windings). The definition of spring is<br />

less complicated than readable.<br />

Simple drawings A few applications<br />

271

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

Saved successfully!

Ooh no, something went wrong!