Jump to:
PurposeThe purpose of the AvanTurtle project is: to assemble a version of LOGO-like graphical drawing language that is more flexible than LOGO, scriptable, and simpler.
The language generates a still image. It can contain line graphs, results from brushes, and combination of other still images. The language however, isn't as fully-featured as LOGO --- it doesn't include many of the logic control elements. It can be written by hand, but it is not targeted as a tutoring language --- another major use of it is using a program to generate the instructions, and let it draw the image.
Mode DesignThe operation of the language is based on modes. Initially there is one mode. Mode A can invoke (or call) another Mode B, and in this case, we call "Mode B runs based on Mode A". The program flow is not parallel. This means when Mode A calls Mode B, Mode A is suspended until Mode B returns. Thus the program flow is quite like a single thread. The initial mode is called the "main mode". The concept of "turtle" is like the LOGO turtle. It represents the draw status (mentioned below).
At the beginning of a mode, the 2D-coordinate system, including the angle and the axis, is a specific value. Initially at the main mode, the positive direction of the Y-axis is upwards, and the starting point is (0, 0). We call this starting point and direction of the Y-axis "home status". Then the turtle can begin drawing, or call another mode. If it draws, the status changes with the draw command issued, and the next draw command has a new status, which is called the "draw status". If it calls another mode, the draw status of the calling mode will define the home status of the called mode, but on returning, the last draw status of the called mode will not affect the draw status of the calling mode. Comparing with other programming languages, mode calls are just like function calls.
To define a mode, use "MODE <mode_name> ... END MODE". To call a mode, use "CALL MODE <mode_name>".
As a mode can be embedded in another mode, the level of embedding is only limited by the amount of available memory.
Instruction DesignThe instructions are divided into several categories: draw instructions, color instructions, math instructions and flow instructions. The draw instructions are divided into two categories: absolute instructions and relative instructions. Below table shows the draw instructions. Also, there is a guideline for designing instructions.
Color instructions are listed in the table below. AvanTurtle, since it runs on Windows platform, supports 24bpp, that is, true color.
Math instructions are listed in the table below. They are for convenient 2D operations, but are not exhaustive.
Flow instructions are listed in the table below.
Escaped string specificationThe escaped string for AvanTurtle is defined as follows: the string begins with a double quote ("), and ends with a double quote. Some characters are special in a string: they include double quote, backslash ("\"), tab, line-feed, carriage-return and other non-printable characters. In order to represent them, an escape sequence needs to be used. We use a way similar to ECMAScript (javascript): we use "\u" and four hexadecimal digits to represent a UTF-16 16-bit value. We also use other escape sequences. See the table below.
Number literal specificationNumber literal specification: a number literal begins with a number, a minus sign or a dot. It has a significand (mantissa) part and optional exponent part. The significand part begins an optional minus sign, and followed by a fraction. The fraction part has an optional integer part, a optional dot and an optional number following the dot. At least one of the interger part and the dot must be present. In the exponent part, there is a mandatory "E" (case-insensitive) and a integer number which can be negative. This is an exponent with base ten.
Instruction design guidelinesFor all AvanTurtle instructions, ease of parsing is considered. To achieve this, all simple instructions should either have a fixed list of arguments, or in the case when the instruction has multiple forms, the argument count can easily be determined by some keyword after the instruction. However, the "REPEAT" instruction is a special case, because it allows embedding other instructions in brackets. For simple instructions, there is no special line-ending character. They terminate by determining the end through keywords without ambiguity.
For example, "FD x" has a fixed list of arguments: the number of pixels to go forward. The instruction "END" can be followed by a keyword "MODE" to make up a two-word instruction "END MODE".
Besides keywords, there are two types of arguments: string literals and numbers. The format of a string literal is defined in escaped string specification. The format of a number is like a conventional floating point number representation in the C programming language, with detailed specification here.
Notes on parsing "REPEAT"To parse REPEAT, first we should identify the instruction REPEAT. Then, we locate the number and the opening bracket "[". Then we let the parser go along, parsing instructions inside it. During the parsing, it will encounter other instructions, and possibly other REPEAT instructions. Whenever it encounters a "]", which doesn't belong to any REPEAT instruction inside, then we can let it return and conclude that this is the end of the outer REPEAT.
Platform ChoiceThe platform for the AvanTurtle program is currently .NET Framework 2.0, using language C# 2.0, with optionally C++/CLI when necessary. Though there are cross-platform options like FreeBASIC/Java, but C# can also be ported using Mono, and usually its performance is higher than Java, and when necessary, C++/CLI can be used to boost the performance.
Image output can be to PNG, JPG, GIF (single frame) or BMP. Note that PNG supports alpha channel, so when using PNG output, all pixels drawn are non-transparent, and all pixels not drawn are transparent. If there is LDIM instruction that loads a PNG image with alpha channel, the result is that the image alpha will also affect the resulting alpha.
QuestionsMiscellaneousThis story is based on a dream I had during the night of 2010-10-28, before which HyoYeung invited me to a dinner at Ajisen Ramen.
|