Path: | readme |
Last Update: | Wed Feb 08 16:37:26 W. Europe Standard Time 2006 |
RubyLogo contains three main components. A Turtle-Graphics implementation for Ruby, a parser to translate Logo code for the turtle and a graphical user interface providing an editor with an integrated drawing area for a Logo turtle. The turtle can also be used directly in Ruby code in through a standalone version which automatically creates a seperate output window during object initialization.
The program understands the following syntax:
forward x: | move the turtle x steps forward |
fd x: | alias for forward x |
backward x: | move the turtle x steps backward |
bk x: | alias for backward x |
right x: | turn the turtle x degrees to the right |
rt x: | alias for right x |
left x: | turn the turtle x degrees to the left |
lt x: | alias for left x |
move x y: | move the turtle to the coordinates (x, y) |
home: | move the turtle to its starting coordinates |
turn x: | turn the turtle into the absolute direction x (clockwise rotation, 0° being the starting direction) |
reset: | return turtle into its starting position, remove all drawn lines but retain functions and variables |
penup: | raise pen from drawing area |
pu: | alias for penup |
pendown: | lower pen onto drawing area |
pd: | alias for pendown |
hide: | make the turtle invisible |
show: | make the turtle visible |
color name: | change the turtle’s color to name |
fg name: | alias for color name |
background name: | change the background color to name |
bg name: | alias for background name |
repeat x code end: | repeat code for x times |
if condition then code end: | execute code only if condition is true |
while condition do code end: | execute code repeatedly as long as condition is true |
def name [variables] code end: | define a function with optional variables. Calling the function through the command name will execute code. Functions must be called with the correct number of arguments. |
to name [variables] code end: | alias for def name [variables] code end |
The parser supports use of variables. Variable names start with : followed by at least one letter or cipher. Variables must be initialized before they are used. :variable = x will initialize :variable with the given value. x may be a number, a mathematical expression or another variable. Expressions are evaluated and the result is assigned to the variable. If x is another variable, its value will be assigned, not the variable itself. If a variable assignment occurs immediately at the beginning of a function definition, use a new line to prevent the parser from interpreting the variable as a function parameter.
Parameters x and y for commands may be positive or negative numbers, variables or mathematical expressions. Expressions will be evaluated and the command will be executed with the result as parameter.
The parameter for the commands color and background can be any combination of letters and ciphers. If the given name is a valid color description depends on the interface which implements the LogoTurtle.
Conditions for code blocks are two numbers, variables or expressions which are compared through one of the following operators: <, <=, >, >=, ==, != If the comparison is true, the associated block will be executed, otherwise it will be ignored.
Function names may contain letters and numbers but must begin with a letter. During definition an optional number of variable names (starting with :) may be assigned and then used inside the function’s code block. A function must be called with an equivalent number of values. These values will be assigned to their respective variables during the execution of the function. If a variable has the same name as a function variable, its value will be overwritten during function calls. Parameters must be variables or numbers. If you want to use a mathematical expression as parameter, assign it to a variable and call the function with the new variable.
Code blocks for repeat, if, while and functions may contain any normal syntax. Multiple levels of blocks may be nested.
Mathematical expressions may contain numbers, parentheses, the mathematical operations -, +, *, /, %, **, cos(), exp(), log(), log10(), sin(), sqrt(), tan(). Expressions that cannot be evaluated will result in the number 0 and a warning message.
# or ; mark the beginning of a comment. The rest of the current line will be ignored by the parser.
Commands and their attributes, blocks and their conditions (including then/do), functions and their variables during definition or call must be on the same line. Line breaks between different commands, beginning or end of code blocks, before or after end statements are allowed but optional. Spaces and tabs are allowed but mostly optional. The only situations in which at least one space, tab or newline is required are before the end keyword and after variables, color names or function names.