Tutorial

tortue-logo makes possible to create drawings with the LOGO language.

You can enter command in the input bar on the top of the page. The commands allow to move the turtle.

Enter the following commande: fd 100 and press Enter or the 1st button at the the right of the input bar.

The turtle has moved hroizontally on the right. It has drawn a 100 pixel line.

The turtle is displayed by the following symbol. A circle with an inner radius line. The direction of the turtle is indicated by this line.

It is possible to change the direction and let it turn on the right or the left.

The rt 90 command make the turtle turning of a 90 degrees angles. lt 90 do the same on the left.

You can enter commands individually in the input bar or add several commands in one time thanks to the multi-line editor taht pops up when clicking on the 2nd button at the rigjt pf the input bar. When clciking Ok in the editor, the whole commands are executed.

In case of error, a message us displayed below the input bar.

You can draw a square with several fd 100 rt 90 commands. You can of course change the size of the square by giving a different a number of pixels to go forward or to male another kind of figure by changing the rotation angle.

For example, the following script draws a triangle:

fd 150
rt 120
fd 150
rt 120
fd 150

It is possible with these simple commands to make a lot of different drawings. However, you may note that in the previous example, the same commands are used several times. The repeat command make possible to write a simpler version of the previous code.

For example: repeat 3 [fd 150 rt 120] draws a triangle too. The fd 150 and rt 120 commands are repeated 3 times.

Before to try this new command, you may want to clean the drawing area and move the turtle to the initial position. This can be done with the cs command. 

We know now how to draw a triangle easily thanks to the repeat command. However, you may find boring to rewrite the same code every time you want to draw a triangle.

To make that easier, you can create your own commands called functions. This is possible with the for command.

For example for triangle repeat 3 [fd 150 rt 120] end create a new command that will execute the code before the end.

We can now call this function by entering its name, triangle, in the input bar.

The command triangle will execute the code repeat 3 [fd 150 rt 120] as we defined.

We can now draw as many triangles as we want. But they will all have the same size. It is possible to change that by passing an argument to the function. Let's modify the triangle function with the following code:

for triangle :x repeat 3 [fd :x rt 120] end

You may note that just after the name the :x string has been added. This is the argument of the function. It can be whatever you want but can not have spaces. It must also be prefixed with the semi-column character (:)

The arguments can be used inside the code of the function. In this case, we use :x as the length of a triangle side.

We can niw draw a triangle and change the size. triangle 10 will draw a 10 pixels triangle.

The functions are kept memory inside the web page. If you refersh your browser, you will lose it. Hopefully, you can now create an account on the tortue-logo server and save your work.

The save triangle command make possible to store the function and to get it back new time by calling the load triangle command.

There are some other interseting commands like setpc et setpw for changing the color or the width of the line. Please read the online help to get the full list of available commands.

Now let's play. Create beautiful drawings and get programmings basics in a funny way.

x