Turtle LibreLogo
Tilbake til startsida
 

 

How to Move the Turtle

In addition to move the turtle with the menu buttons, you can also may move it in all directions, and all lengths with written commands. If a command will move the turtle a number will tell how many pixels it should be moved. If the command will turn the turtle the number will tell how many degrees. (360 ​​° is a total circle). Write the command on the command line and press Enter to execute the command.

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

LEFT 90 will turn the turtle 90° to the left (counterclockwise). 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 straight up, 270 ° is directly to the left, and so forth.

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

Now we have the most important commands for moving the turtle. Write on the command line the code you find below. Press the Enter key after each line. It is not necessary to write the code after semicolon (;). Semicolon tells that the part after is not a part of the program, but an explanation of 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

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

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

It is possible to enter several commands on the command line. 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 sceen 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 PEN UP. To draw a visible line, use the command PEN DOWN.

Measurement units

If you writes lengths and angles without a measurment unit, LibreLogo will use the default units: pixel and degrees. (Pixels are the dots which creates 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 lowercase without spaces between the number and unit of measure. Other measurements are "mm" and "inch". Instead of degrees, you can use the dial of the clock. Command RIGHT 4h will turn the turtle pointing at 4 o'clock. These different unit can also be written as decimal numbers. RIGHT 9.5h and FORWARD 2.75cm exerts fine.

Other contols for the turtle

Function above it is the fundamental commands for moving cuticle toad, but there are other ways of controlling the turtle. Here are some of them.

Location on screen

POSITION [x, y] places the turtle in coordinates (x, y) on the screen. As usual are (0,0) 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 in relation to the location as it had from before. Is the pen 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 screen. You can have a specified control this by defining two variants, for example :maxX and :maxY to get the coordinats of the lower right corner of the page and use these in other commands. An example: First get the coordinats 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 rotates 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 she has from before. Direction is (usually) set in degrees, where 0 is straight up. HEADING 180 will rotate the turtle facing down. You can also specify the direction as coordinats: HEADING [200, 300] or in relation to the hour: HEADING 9h will turn the turtle 9 o'clock. (Note small 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 do 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. You easily get the turtle reappear with the command SHOWTURTLE.

Blank out the screen

To start over again with a clean screen, use the command CLEARSCREEN. This command removes all that is 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 the writing

LibreLogo has, like any other language, some writing rules that are important. Among others these:
● 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 the menu "Name" for a complete list.


© Context and design: Kolbjørn StuestølStuestøl homesite (in Norwegian)Modified 2. desember 2015