[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5. Programming
Here is a short introductory example to the Asymptote
programming
language that highlights the similarity of its control structures
with those of C, C++, and Java:
// This is a comment. // Declaration: Declare x to be a real variable; real x; // Assignment: Assign the real variable x the value 1. x=1.0; // Conditional: Test if x equals 1 or not. if(x == 1.0) { write("x equals 1.0"); } else { write("x is not equal to 1.0"); } // Loop: iterate 10 times for(int i=0; i < 10; ++i) { write(i); }
Asymptote
supports while
, do
, break
, and
continue
statements just as in C/C++. It also supports the Java-style
shorthand for iterating over all elements of an array:
// Iterate over an array int[] array={1,1,2,3,5}; for(int k : array) { write(k); }
In addition, it supports many features beyond the ones found in those languages.
5.1 Data types | void, bool, int, real, pair, triple, string | |
5.2 Paths and guides | ||
5.3 Pens | Colors, line types, line widths, font sizes | |
5.4 Transforms | Affine transforms | |
5.5 Frames and pictures | Canvases for immediate and deferred drawing | |
5.6 Files | Reading and writing your data | |
5.7 Variable initializers | Initialize your variables | |
5.8 Structures | Organize your data | |
5.9 Operators | Arithmetic and logical operators | |
5.10 Implicit scaling | Avoiding those ugly *s | |
5.11 Functions | Traditional and high-order functions | |
5.12 Arrays | Dynamic vectors | |
5.13 Casts | Implicit and explicit casts | |
5.14 Import | Importing external Asymptote packages
| |
5.15 Static | Where to allocate your variable? |
[ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |