First 3968 steps
The LOGO programming language has been associated with turtle graphics since its beginning.
It is a method of drawing by issuing simple shift and turn commands to the turtle. On the screen, the turtle
is symbolized by an arrow icon. Its first step is as follows:
forward 50 |
|
Type the instruction into a command line and press Enter. The turtle will move forward and draw
a section with the length of 50 (default drawing scale is 1:1, so the distance of 50 corresponds to 50 points
on the screen). The forward
instruction requires one argument. The argument denotes the distance
the turtle will cover while moving forward, in the direction indicated by the arrow.
And this is the first turn - to the right, by 90 degrees (typed as the right
command
argument):
right 90 |
|
After repeating these commands another three times, you will finish drawing the square:
forward 50
right 90
forward 50
right 90
forward 50
right 90
|
|
However, constant repetition of the same commands is neither correct nor interesting. It is
better to draw the same square using a so-called loop - one of the basic elements of all the programming
languages, which allows to execute the sequence of commands many times.
To clear the previous square, type the command:
And now the loop:
repeat 4 [forward 50 right 90] |
|
The repeat
loop needs two arguments: a number of repetitions (in this case: 4) and
a command list to be executed. In LOGO, the list is created by typing words within square brackets. The words
from the list will be interpreted as commands and their arguments. You can check how LOGO understood your
previous commands by tracing them with a cursor in the command history. The command is marked with blue and
its arguments are in yellow. If one command is an argument for another, more outer one, you will see the outer
command marked with lighter blue, etc.
Taking many small steps and turns, you can get the impression that you are drawing smooth curves,
for example a circle consists of 360 1-point steps forward, with a 1-degree turn after each step (don’t forget
about clearscreen
, you can use: cs
as the command abbreviation as well):
repeat 360 [forward 1 right 1] |
|
Drawing in LOGO is the art of expressing complicated formulas as simple commands. Let’s try such a loop:
repeat 3600 [fd 10 rt repcount + 0.1] |
|
Some new commands came up here - two abbreviations, to be precise: fd
for forward
that we are already familiar with,
rt
for right
, and a new command: repcount
, which allows to read current number of loop repetitions.
In order to understand better how this command works, write its value in the text window, using the
print
command:
repeat 5 [print repcount] |
|
Printing values helps to create programs and understand how their work.
In the meantime, if you count, the turtle has already done 3968 steps forward
. What’s next?
Functions and variables.