Logo - Turtle

The simple Logo Drawing Commands move the Turtle forward and backward and also turn it right or left. The commands and their abbreviations are given below −

• fd – forward
• bk – backward
• rt – right
• lt – left
• cs – clearscreen

Either version of these commands can be used. Except the cs command, each of these commands must be followed by one value called as its argument. The arguments for fd and bk are units; those of rt and lt are angles that can be any integer. A rotation by 360 is a complete rotation, therefore a rotation by 375 degrees is the same as 1/15 degrees.

• forward 60 or fd 60 means go forward 60 steps

• right 90 or rt 90 means right turn 90 degrees

• left 90 or lt 90 means left turn 90 degrees

• back 60 or bk 60 means go back 60 steps

• clearscreen or cs means erase all drawings. This sets the turtle at the center

The graphics window has a coordinate system. The values of the two coordinates (normally called x and y) at the center are 0, 0. At the northeast corner, they are 250, 250; at the southeast corner, they are 250, -250. At the southwest corner, they are -250, -250; etc. If the turtle tries to walk off onto one side of the screen, it wraps around. The right side wraps to the left side and the top wraps to the bottom.

Many programming systems work on the same kind of two-axis ‘xy’ coordinate plane, which we work with in Algebra as well.

Here, ‘0 0’ is the center, or origin (no comma or parentheses here!). In its centered, zoom-"normal" state, Logo's drawing screen shows an area of about 150 points up or down and 300 points right or left from the center.

The turtle can be directed with headings that correspond to a compass rose, with 0 or 360 degrees pointing straight up, 90 degrees straight to the right, and so on. You can set a variable to a number between 0 and 360 and then walk on that path.

Turtle Commands

Now let us try some commands. Commands will be issued one per line followed by a carriage return. Several of these commands can be typed in succession in a command window followed by a carriage return. The effect on the turtle is the same. However, if you type a command, which requires one or more inputs and provide the missing input(s) on the next line, Logo will show an error.

Following is a practice command, which shows the desired results on the right.

The commands – fd 50 rt 120 fd 50 rt 120 fd 50 rt 120, cause the turtle to draw a triangle, as you can see by trying them out.

These commands are read from the left to the right. Since the command fd requires one argument, it is taken as the next value. Similarly, rt takes an argument as well. Thus, Logo can give an unambiguous meaning to each of these character strings. For some Logo commands, separators are needed.

Following are few practice commands with the desired results on the right.

Following is an exercise to check your aptitude on what you have learned so far in this chapter.