0% found this document useful (0 votes)
18 views

Asymptote Reference Card (J. C. Bowman) (v1.1 - May 2014)

This document provides reference information on the syntax and commands for the Asymptote programming language. It includes details on data types, functions, control flow, arrays, paths, pens, labels, clips and fills. The reference card covers the basic building blocks for working with vectors, images, and 3D graphics in Asymptote.

Uploaded by

Alireza Takrimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Asymptote Reference Card (J. C. Bowman) (v1.1 - May 2014)

This document provides reference information on the syntax and commands for the Asymptote programming language. It includes details on data types, functions, control flow, arrays, paths, pens, labels, clips and fills. The reference card covers the basic building blocks for working with vectors, images, and 3D graphics in Asymptote.

Uploaded by

Alireza Takrimi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Asymptote Reference Card Operators

arithmetic operations + - * /
Program structure/functions modulus (remainder) %
import "filename" import module comparisons == != > >= < <=
import "filename" as name import filename as module name not !
include "filename" include verbatim text from file and or (conditional evaluation of RHS) && ||
type f (type,. . . ); optional function declaration and or xor & | ^
type name; variable declaration cast expression to type (type) expr
type f (type arg,. . . ) { function definition increment decrement prefix operators ++ --
statements assignment operators += -= *= /= %=
return value; conditional expression expr 1 ? expr 2 : expr 3
} structure member operator name.member
expression evaluation separator ,
Data types/declarations
boolean (true or false) bool Flow control
tri-state boolean (true, default, or false) bool3 statement terminator ;
integer int block delimeters { }
float (double precision) real comment delimeters /* */
ordered pair (complex number) pair comment to end of line delimiter //
character string string exit from while/do/for break;
fixed piecewise cubic Bezier spline path next iteration of while/do/for continue;
unresolved piecewise cubic Bezier spline guide return value from function return expr ;
color, line type/width/cap, font, fill rule pen terminate execution exit();
label with position, alignment, pen attributes Label abort execution with error message abort(string);
drawing canvas picture Flow constructions (if/while/for/do)
affine transform transform
constant (unchanging) value const if(expr ) statement
allocate in higher scope static else if(expr ) statement
no value void else statement
inhibit implicit argument casting explicit while(expr )
structure struct statement
create name by data type typedef type name for(expr 1 ; expr 2 ; expr 3 )
statement
3D data types (import three;)
for(type var : array )
ordered triple triple statement
3D path path3
do statement
3D guide guide3
while(expr );
3D affine transform transform3
Constants
exponential form 6.02e23
TEX string constant "abc. . . de"
TEX strings: special characters \\, \"
C strings: constant ’abc. . . de’
C strings: special characters \\, \" \’ \?
C strings: newline, cr, tab, backspace \n \r \t \b
C strings: octal, hexadecimal bytes \0-\377 \x0-\xFF

1
Arrays fill commands
array type[] name; fill path with current pen fill(path)
array element i name[i] fill path with pen fill(path,pen)
array indexed by elements of int array A name[A] fill path on picture fill(picture,path)
anonymous array new type[dim]
array containing n deep copies of x array(n,x) label commands
length name.length label a pair with optional alignment z label(Label,pair,z)
cyclic flag name.cyclic label a path with optional alignment z label(Label,path,z)
pop element x name.pop() add label to picture label(picture,Label)
push element x name.push(x)
append array a name.append(a) clip commands
insert rest arguments at index i name.insert(i,. . . ) clip to path clip(path)
delete element at index i name.delete(i) clip to path with fill rule clip(path,pen)
delete elements with indices in [i,j] name.delete(i,j) clip picture to path clip(picture,path)
delete all elements name.delete()
test whether element n is initialized name.initialized(n)
pens
array of indices of initialized elements name.keys Grayscale pen from value in [0,1] gray(g)
complement of int array in {0,. . . ,n-1} complement(a,n) RGB pen from values in [0,1] rgb(r,g,b)
deep copy of array a copy(a) CMYK pen from values in [0,1] cmyk(r,g,b)
array {0,1,. . . ,n-1} sequence(n) RGB pen from heximdecimal string] rgb(string)
array {n,n+1,. . . ,m} sequence(n,m) heximdecimal string from rgb pen] hex(pen)
array {n-1,n-2,. . . ,0} reverse(n) hsv pen from values in [0,1] hsv(h,s,v)
array {f(0),f(1),. . . ,f(n-1)} sequence(f,n) invisible pen invisible
array obtained by applying f to array a map(f,a) default pen defaultpen
uniform partition of [a,b] into n intervals uniform(a,b,n) current pen currentpen
concat specified 1D arrays concat(a,b,. . . ) solid pen solid
return sorted array sort(a) dotted pen dotted
return array sorted using ordering less sort(a,less) wide dotted current pen Dotted
search sorted array a for key search(a,key) wide dotted pen Dotted(pen)
index of first true value of bool array a find(a) dashed pen dashed
index of nth true value of bool array a find(a,n) long dashed pen longdashed
dash dotted pen dashdotted
Initialization long dash dotted pen longdashdotted
initialize variable type name=value; PostScript butt line cap squarecap
initialize array type[] name={. . . }; PostScript round line cap roundcap
PostScript projecting square line cap extendcap
path connectors miter join miterjoin
straight segment -- round join roundjoin
Beziér segment with implicit control points .. bevel join beveljoin
Beziér segment with explicit control points ..controls c0 and c1..pen with miter limit miterlimit(real)
concatenate & zero-winding fill rule zerowinding
lift pen ^^ even-odd fill rule evenodd
..tension atleast 1.. :: align to character bounding box (default) nobasealign
..tension atleast infinity.. --- align to TEX baseline basealign
pen with font size (pt) fontsize(real)
Labels LaTeX pen from encoding,family,series,shape font(strings)
implicit cast of string s to Label s TEX pen font(string)
Label s with relative position and alignment Label(s,real,pair) scaled TEX pen font(string,real)
Label s with absolute position and alignment Label(s,pair,pair) PostScript font from strings Courier(series,shape)
Label s with specified pen Label(s,pen) pen with opacity in [0,1] opacity(real)
construct pen nib from polygonal path makepen(path)
draw commands pen mixing operator +
draw path with current pen draw(path)
draw path with pen draw(path,pen)
draw labeled path draw(Label,path)
draw arrow with pen draw(path,pen,Arrow)
draw path on picture draw(picture,path)
draw visible portion of line through two pairs drawline(pair,pair)

2
path operations affine transforms
number of segments in path p length(p) identity transform identity()
number of nodes in path p size(p) shift by values shift(real,real)
is path p cyclic? cyclic(p) shift by pair shift(pair)
is segment i of path p straight? straight(p,i) scale by x in the x direction xscale(x)
is path p straight? piecewisestraight(p) scale by y in the y direction yscale(y)
coordinates of path p at time t point(p,t) scale by x in both directions scale(x)
direction of path p at time t dir(p,t) scale by real values x and y scale(x,y)
direction of path p at length(p) dir(p) map (x, y) → (x+sy, y) slant(s)
unit(dir(p)+dir(q)) dir(p,q) rotate by real angle in degrees about pair z rotate(angle,z=(0,0))
acceleration of path p at time t accel(p,t) reflect about line from P--Q reflect(P,Q)
radius of curvature of path p at time t radius(p,t)
precontrol point of path p at time t precontrol(p,t)
string operations
postcontrol point of path p at time t postcontrol(p,t) concatenate operator +
arclength of path p arclength(p) string length length(string)
time at which arclength(p)=L arctime(p,L) position ≥ pos of first occurence of t in s find(s,t,pos=0)
point on path p at arclength L arcpoint(p,L) position ≤ pos of last occurence of t in s rfind(s,t,pos=-1)
first value t at which dir(p,t)=z dirtime(p,z) string with t inserted in s at pos insert(s,pos,t)
time t at relative fraction l of arclength(p) reltime(p,l) string s with n characters at pos erased erase(s,pos,n)
point at relative fraction l of arclength(p) relpoint(p,l) substring of string s of length n at pos substr(s,pos,n)
point midway along arclength of p midpoint(p) string s reversed reverse(s)
path running backwards along p reverse(p) string s with before changed to after replace(s,before,after)
subpath of p between times a and b subpath(p,a,b) string s translated via {{before,after},. . . } replace(s,string [][] table)
times for one intersection of paths p and q intersect(p,q) format x using C-style format string s format(s,x)
times at which p reaches minimal extents mintimes(p) casts hexidecimal string to an integer hex(s)
times at which p reaches maximal extents maxtimes(p) casts x to string using precision digits string(x,digits=realDigits)
intersection times of paths p and q intersections(p,q) current time formatted by format time(format="%a %b %d %T %Z %Y")
intersection times of path p with ‘--a--b--’ intersections(p,a,b) time in seconds of string t using format seconds(t,format)
intersection times of path p crossing x =x times(p,x) string corresponding to seconds using format time(seconds,format)
intersection times of path p crossing y =z.y times(p,z) split s into strings separated by delimiter split(s,delimiter="")
intersection point of paths p and q intersectionpoint(p,q)
intersection points of p and q intersectionpoints(p,q)
intersection of extension of P--Q and p--q extension(P,Q,p,q)
lower left point of bounding box of path p min(p)
upper right point of bounding box of path p max(p)
subpaths of p split by nth cut of knife cut(p,knife,n)
winding number of path p about pair z windingnumber(p,z)
pair z lies within path p? interior(p,z)
pair z lies within or on path p? inside(p,z)
path surrounding region bounded by paths buildcycle(. . . )
path filled by draw(g,p) strokepath(g,p)
unit square with lower-left vertex at origin unitsquare
unit circle centered at origin unitcircle
circle of radius r about c circle(c,r)
arc of radius r about c from angle a to b arc(c,r,a,b)
unit n-sided polygon polygon(n)
unit n-point cyclic cross cross(n)
pictures
add picture pic to currentpicture add(pic)
add picture pic about pair z add(pic,z)

May 2014 v1.1. Copyright c 2014 John C. Bowman

Permission is granted to make and distribute copies of this card, with or


without modifications, provided the copyright notice and this permission
notice are preserved on all copies.

You might also like