To draw a line from coordinate (0,0) to coordinate (100,100) using
Asymptote
's interactive mode, type at the command prompt:
asy draw((0,0)--(100,100));
The units here are PostScript
"big points"
(1 bp
= 1/72 inch
); --
means join with a linear segment.
At this point you can type in further draw commands, which will be added
to the displayed figure, or type quit
to exit interactive mode.
You can use the arrow keys in interactive mode to edit previous lines
(assuming that you have support for the GNU readline
library
enabled). Further commands specific to interactive mode are described
in Interactive mode.
In batch mode, Asymptote
reads commands directly from a
file. To try this out, type
draw((0,0)--(100,100));into a file, say test.asy. Then execute this file by typing the command
asy -V test
MSDOS
users can drag and drop the file onto the
Desktop asy
icon or make Asymptote
the
default application for files with the extension asy
.
The -V
option opens up a PostScript
viewer window so you can immediately view the encapsulated
PostScript
output. By default the output will be written to the
file test.eps
; the prefix of the output file may be changed with
the -o
command line option.
One can draw a line with more than two points and create a cyclic path like this square:
draw((0,0)--(100,0)--(100,100)--(0,100)--cycle);
It is often inconvenient to work directly with PostScript
coordinates.
The next example draws a unit square scaled to width 101 bp and height
101 bp. The output is identical to that of the previous example.
size(101,101); draw((0,0)--(1,0)--(1,1)--(0,1)--cycle);
For convenience, the path (0,0)--(1,0)--(1,1)--(0,1)--cycle
may be replaced with the predefined variable
unitsquare
, or equivalently, box((0,0),(1,1))
.
One can also specify the size in pt
(1 pt
= 1/72.27 inch
),
cm
, mm
, or inches
.
If 0 is given as a size argument, no restriction is made in that direction;
the overall scaling will be determined by the other direction
(see size):
size(0,3cm); draw(unitsquare);
To make the user coordinates represent multiples of exactly
1cm
, fit the picture like this:
draw(unitsquare); shipout(unitsize=1cm);
Adding labels is easy in Asymptote
; one specifies the
label as a double-quoted LaTeX
string, a
coordinate, and an optional alignment direction:
size(0,3cm); draw(unitsquare); label("$A$",(0,0),SW); label("$B$",(1,0),SE); label("$C$",(1,1),NE); label("$D$",(0,1),NW);
See section graph (or the online Asymptote
gallery at
http://asymptote.sourceforge.net) for further examples, including
two-dimensional scientific graphs.