Drawing Definition FIle
A drawing definition file consists of a sequence of variable definition lines followed by lines with named command strings. It is possible to mix the order of variable definitions and command strings but it helps with readability to put all variable definitions first.
The exact syntax of these lines is defined below but common to both the variable definitions and command strings is the fact that they must both end in a semicolon. Anything after the semicolon is ignored and can be used as comments.
A line beginning with a semicolon is ignored and can be used as a comment line. Any line that does not contain a semicolon is also ignored. If a drawing fails to execute properly check that all variable definitions and command strings end in a semicolon otherwise they are ignored.
Note that the names of all variables, functions and commands are case sensitive. In other words, the variable x is different than the variable X.
Variable Definition Lines
A variable definition line takes the form of a variable name followed by an equal sign followed by a mathematical formula ending with a semicolon. There can be only one variable definition per line.
The variable name can be any alphanumeric string that does not contain whitespace. The mathematical formula can be any standard mathematical expression involving the operators +, -, *, /, ^(exponentiation), (, ), and the following functions
- sqrt(x)
Returns the positive square root of x. x must be a positive real number. - cos(x)
Returns the cosine of x which will be in the range -1 to +1. The variable x must be in radians. To convert from degrees to radians multiply by pi/180. - sin(x)
Returns the sine of x which will be in the range -1 to +1. The variable x must be in radians. To convert from degrees to radians multiply by pi/180. - tan(x)
Returns the tangent of x. x must be in radians. To convert from degrees to radians multiply by pi/180. Note that tan(x) goes to infinity as x approaches an odd integer multiple of pi/2. - acos(x)
Returns the arc cosine of x in units of radians. This is the angle whose cosine is x. The value returned will be in the range 0 to pi. - asin(x)
Returns the arc sine of x in units of radians. This is the angle whose sine is x. The value returned will be in the range -pi/2 to pi/2. - atan(x)
Returns the arc tangent of x in units of radians. This is the angle whose tangent is x. The value returned will be in the range -pi/2 to pi/2. - angle(x,y,z)
For a triangle with sides of length x, y, z, this returns the angle common to the sides of length x and y. The angle is in units of radians. - exp(x)
Returns the base of the natural logarithm raised to the power of x. - log(x)
Returns the natural logarithm of x. To find the logarithm with respect to the base b divide the result by log(b).
A mathematical expression can contain previously defined variables. The variable pi=3.14159265359 is always predefined. Arguments and return values for all trigonometric functions are in terms of radians where pi radians is equal to 180 degrees.
Named Command Strings
A named command string takes the form of a name followed by a colon followed by a string of commands ending in a semicolon. The name can be any alphanumeric string that does not contain whitespace. Commands may or may not be separated by white space. To enhance readability at least one blank space should be placed between commands but it is not strictly necessary. Names are used in the substitution command defined below. It can also be used to specify the starting string of drawing commands by passing it to the nell program as a parameter.
The following is a list of the possible commands that may appear in a command string. Examples of how to use these commands are given in the following chapters.
- L(l)
Draws a straight line of length l in the current direction starting at the current position. After this command the current position is updated to the point at the end of the line. The current direction is not changed. - Q(l,lc,ac)
Draws a quadratic Bezier curve that connects to a point a distance l in the current direction from the current position. The direction of the control point is at angle ac from the current direction. For ac>0 this is to the left of the current direction (counterclockwise) and for ac<0 it is to the right (clockwise). lc is the distance of the control point from the current point. After this command the current position is updated to the point at the end of the curve. The current direction is not changed. - B(l,lc1,ac1,lc2,ac2)
Draws a cubic Bezier curve that connects to a point a distance l in the current direction from the current position. lc1 is the distance of the first control point from the start of the curve. lc2 is the distance of the second control point from the end of the curve. ac1 is the direction of the first control point measured with respect to the current direction at the start of the curve. ac2 is the direction of the second control point measured with respect to the current direction at the end of the curve. For both directions, positive values are to the left and negative values are to the right of the current direction. After this command the current position is updated to the point at the end of the curve. The current direction is not changed. - C(r)
Draws a circle of radius r centered at the current position. Neither the current position or direction are changed. A circle cannot be part of a path. - E(rx,ry)
Draws an ellipse centered at the current position. The x and y radii of the ellipse are given by rx and ry. The ellipse is rotated so that the x-axis is in the current direction. Neither the current position or direction are changed. An ellipse cannot be part of a path. - R(rx,ry,a,da)
Draws an arc of an ellipse centered at the current position. The x and y radii of the ellipse are given by rx and ry. The ellipse is rotated so that the x-axis is in the current direction. The starting point of the arc is at angle a from the current direction. For a>0 this is to the left of the current direction (counterclockwise) and for a< it is to the right (clockwise). The angle swept out by the arc from the starting to the ending point is da. For da>0 the arc from start to end goes counterclockwise around the ellipse and for da< it goes clockwise. Neither the current position or direction are changed. An elliptic arc cannot be part of a path. - M(l)
Moves a distance l in the current direction from the current point. After this command the current position is updated to the new point. The current direction is not changed. - T(da)
Changes the current direction by the angle da. For da>0 the new direction is counterclockwise from the current direction and for da< it is clockwise. The current position is not changed. - P(x,y)
Sets the current position to the point (x,y). The current direction is not changed. - D(a)
Sets the current direction to the angle a. The current position is not changed. - Z()
Draws a line from the current position to the position at the start of the current path. The current position and direction are updated to the values at the start of the current path. The most common use of this command is at the end of a path just before the > symbol that closes the path but it can be appear anywhere inside a path and can appear more than once. The command takes no arguments. - <
This symbol marks the start of a new path. The current position and direction are used as the starting point of the path so they should be set to the desired values prior to starting the path. Paths cannot be nested so it is an error to use this symbol inside a currently open path. - >
This symbol marks the end of a path. It is an error to use this symbol if there is no currently open path. The current position and direction remain unchanged. - [
Saves the current position and direction. This can be nested up to 64 times. - ]
Restores the most recently saved position and direction. - S(C,n)
Substitutes the command string labeled C n times. A command string can substitute itself recursively. The recursion stops when the maximum recursion level is reached. This level is specified on the command line. - A(var,exp)
Sets the variable var to the value of expression. var can be any previously defined variable or a new variable. exp can be any mathematical expression as described in the section on variable definitions.