Turtle LibreLogo
Tilbake til startsida
 

 

How to Move the Turtle

In addition to moving the turtle with the menu buttons, you can move it in any direction, and any distance with written commands. In a move command there must be a number which sets the number of pixels the turtle should be moved. If the command will turn the turtle, the number will tell how many degrees. (360 ​​° is a full circle). Write the command in the command line and press Enter to execute the command.

You determine the direction in which the turtle will be moved with the commands LEFT, RIGHT and DIRECTION.

LEFT 90 will turn the turtle 90° to the left (counter-clockwise). RIGHT 45 turns the turtle 45° to the right (clockwise) in relation to the angle the turtle has before turning. DIRECTION can also take degrees but then in relation to the screen. 0° is upwards, 270° is to the left, and so forth.

The home place for the turtle is the center of the screen with head upward. If the first command is FORWARD 50 this will move the turtle 50 pixels upwards, whereas BACK 70 will move it 70 pixels downwards. The head is still facing upwards.

Now we have some of the most important commands for moving the turtle. Write in the command line the code you find below. Press the Enter key after each line. It is not necessary to write the comments after the semicolon (;). A semicolon indicates that the following text is not a part of the program, but an explanation to the programmer stating what the command does.

firkant
  • FORWARD 100; Moves the turtle 100 pixels forwards.
  • RIGHT 90; Turns the turtle 90 degrees to the right.
  • FORWARD 100
  • RIGHT 100
  • FORWARD 100
  • RIGHT 100
  • FORWARD 100

LibreLogo has a very simple error function. If there are bugs, a window pops up with a message telling that there is a mistake in the line number x. Sometimes there is also text that is meant to show what the error is, but this text is mostly of little help.

If you have everything right, there will now be a square with sides 100 pixels long on the screen.

It is possible to enter several commands on the command line at the same time. So instead of typing commands above separately, you can enter FORWARD 100 RIGHT 90 and press Enter three times. Erase RIGHT 90 so that only FORWARD 100 remain and press Enter again to complete the last line.

Naturally you should try to create other shapes with other parameters. What about making a hexagon? You can start with a new screen by pressing the buttons Clear screen and Home on the menu bar, or with the commands CLEAR SCREEN and then HOME.

Moving without rendering

To move the turtle without drawing a line, use the command PENUP. To draw a visible line again, use the command PENDOWN.

Measurement units

If you write lengths and angles without a measurement unit, LibreLogo will use the default units: pixel and degrees. (Pixels are the dots which create the image on the screen). You may also use some other units of measurement. FORWARD 10cm will move the turtle 10 cm forward. Note that the measurement unit must be typed in lower case without spaces between the number and unit of measure. Other measurements are “mm” and “inch”. Instead of degrees, you can use a clock face. Command RIGHT 4h will turn the turtle pointing at 4 o'clock. These different units can also be written as decimal numbers. RIGHT 9.5h and FORWARD 2.75cm works fine.

Other controls for the Turtle

Above are the fundamental commands for moving the turtle, but there are other ways of controlling it. Here are some of them.

Location on screen

POSITION [x, y] places the turtle at coordinates (x, y) on the screen. As usual (0,0) is the upper left corner of the screen. In addition to being moved to the location, the turtle is rotated in the direction towards the coordinates. If the pen is down, it also draws a line when moving. There is no control telling you that the turtle is outside the screen. If you write POSITION [3000, 100] the turtle is placed far outside the screen. If you want you can avoid this by defining two variants, for example :maxX and :maxY to get the coordinates of the lower right corner of the page and use these in other commands. An example: First get the coordinates by using :maxX = PAGESIZE [0] and :maxY = PAGESIZE [1] and then use it to set the position of the turtle POSITION [:maxX / 4, :maxY / 3 which will place the turtle ¼ from the left side of the page width, and ⅓ down. (The slash is the division symbol in LibreLogo).

The commands RIGHT and LEFT rotate the turtle in relation to the direction it had before the command was executed. The HEADING command turns the turtle in relation to the screen, regardless of what direction it has from before. Direction is (usually) set in degrees, where 0 is upwards. HEADING 180 will rotate the turtle facing downwards. You can also specify the direction as coordinates: HEADING [200, 300] or in relation to the clock face: HEADING 9h will turn the turtle towards 9 o'clock. (Note lower case h without spaces).

Move home

Another move command is HOME which moves the turtle to the starting point in the center of the screen. It will also be rotated to its start position, with the head upward. The turtle does not draw when it moves back home.

Hiding the turtle

If the picture of the turtle disrupts a drawing you can hide the turtle by typing the command HIDETURTLE. To easily have the turtle re-appear use the command SHOWTURTLE.

Blank out the screen

To start over again with a clean screen, use the command CLEARSCREEN. This command removes all on the screen. The turtle will keep standing where it is. To move the turtle to its starting position, use the command HOME.

A little about writing

LibreLogo has, like any other language, some writing rules that are important:
● There must be a space between the command and the value (number).
● You can enter several commands on the same line with spaces between expressions.
● Commands can be upper case or lower case letters, or a mixture.
● Many commands have several names. Refer to the menu 'Commands' for a complete list. In this document I have written all commands in upper case to clarify that they are commands.


© Context and design: Kolbjørn StuestølStuestøl homesite (in Norwegian)Modified December 27 2015