Asymptote: Olympiad Package Part 1

Revision as of 01:48, 7 January 2010 by Dojo (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Asymptote (Vector Graphics Language)
Getting Started - Basics - Drawing - Labeling - Filling - Useful functions - Examples - Macros and Packages

Help - Reference - Advanced Asymptote - 3D Graphics - CSE5 Package - How to

Sometimes, you don't want to write the coordinate (3.5,6.2) over and over and over again. Thus, the olympiad package is a lifesaver. Let's look at this simple bit of code: (Note, the import olympiad command is not needed on the forum).

import olympiad;
real r=2.5, a=3.5;
dot((r,a));

[asy] import olympiad; real r=2.5, a=3.5; dot((r,a)); [/asy]

Or something like:

import olympiad;
pair A=origin, B=(3,0), C=(3,2), D=(0,2);
draw(A--B--C--D--cycle);

[asy] import olympiad; pair A=origin, B=(3,0), C=(3,2), D=(0,2); draw(A--B--C--D--cycle); [/asy]

(Note that the origin is the point (0,0)).

Now let's go even farther:

import olympiad;
pair A=origin, B=(3,0), C=(3,2), D=(0,2);
path p=A--B--C--D--cycle;
draw(p);

[asy] import olympiad; pair A=origin, B=(3,0), C=(3,2), D=(0,2); path p=A--B--C--D--cycle; draw(p); [/asy]

At the moment, this does nothing to shorten our code. However, in this bit:

import olympiad;
pair A=origin, B=(3,0), C=(3,2), D=(0,2);
path p=A--B--C--D--cycle;
draw(p);
draw(shift(3.5,0)*p);
draw(shift(7,0)*p);

[asy] import olympiad; pair A=origin, B=(3,0), C=(3,2), D=(0,2); path p=A--B--C--D--cycle; draw(p); draw(shift(3.5,0)*p); draw(shift(7,0)*p); [/asy]

the code works nicely. Without defining the path, the code would have been much longer.