Logotron educational software. Partners with the teaching profession - Pioneers in Learning
menubar search this site my shopping cart support products about home
 

Working with Turtles


Defining procedures | Making turtles perform given commands | Click on me
Settlements for project users
| Explore Project Window | Assignments

Task
  • to work with several turtles; to teach each turtle something new; to decide whose command it is; to click on the turtles to paste text into a page
You need to know
  • basic commands for turtle geometry; adding and working with the buttons on the page; the command edit.
You will learn
  • how and where to add new commands; which turtle reacts to these commands; onClick to add event paste the settlements for users on the page.
Defining the procedures
 
You can use the basic command edit (storage ed) to add procedures. Here, let's teach the turtle to draw the letter T.

? ed "letterT

The following dialog box will appear where you can define your new procedure. Write the commands for drawing the letter T. Press OK to close the dialog box, Now you can test your new command:

? letterT

You can define other commands in this way. Modern programming trend guides us to decide which object is related to the given command, which object will perform it and to define the appropriate command especially for the given object. 

This is the most important step towards Object Oriented Programming and you will learn it in following parts of this tutorial. If you do not use OOP, you can define all the commands for the Main Window and all the objects you can see from it.

Making turtles perform given commands

Add a second turtle to the page - select the button from the Main toolbar and click anywhere on the page. A new turtle appears with the name t2. You can change, move, put to front, edit its shape, etc. in its context menu. This turtle is non-active, it is not in the active turtle list and it does not perform the commands in the command line, try:

? clearscreen letterT ; only the original turtle t1 draws the letter T

To make the new turtle t2 active you need to write in the command line:

? tell [t1 t2] ; all the named turtles become active
? clearscreen letterT
;
the letter T is drawn by both the turtles

In the remainder of this task we will address the screen turtles individually. For example:
? t2'letterT ; the letter T is drawn only by the turtle t2

Note: the name of the turtle (or another object) is followed by an apostrophe. It is followed (without the space) by the command to be performed by the turtle. Try:

? t1'forward 100
? t2'left 90

Click on me

In various activities you may wish to give the turtle an on click command. The simplest example of this is to give the turtle a random moving and turning command. Remind yourself what things you have to program in Imagine Logo to reach this effect - watching the clicks, finding if the clicks are on the turtle, what turtle is clicked, putting this together...

The solution in Imagine Logo is very simple - set the event onClick in the turtle's birth certificate

It performs at the moment when the turtle is clicked.

Right click on turtle t1 and in the context menu select Change t1 – its birth certificate will open. The first page has a line with the name onClick at the bottom. Write two commands here: fd any lt any - the word any means random (but for the given command an appropriate input) that means random number of the steps, random turning, it can be used for the commands setPC any, setPW any etc. Close the dialog box by clicking on the OK button. Try out this command. Click on the turtle to move or turn it left with each click.

Settlements for the project users

For this project it would be useful to have an onscreen text, which explains what to do (i.e. click on the turtle to make it move or turn left.

Use the Imagine Logo Text Box to do this. Locate the 'New Text Box' tool from the Main toolbar. Press this button and determine the size of the text be clicking and dragging on the page. Write your information in this text box, change the style, colour and the type size as desired.
   

Explore Project Window

You can explore the Imagine Logo project via the Explore Project window (press F4 or choose Explore from the View menu). Imagine Logo supports object programming, you can therefore find individual objects - for example Page1 and the turtles t1, t2 on it, in the Explore Project Window.
 

Assignments
  1. Define some commands for the turtle t2 for example let it also move randomly, but with various pen widths and various pen colours.
  2. Put a button on the page to clear the screen and return the turtles in their home positions.
  3. Paste another turtle on the page; it can draw coloured squares by clicking on it.
  4. Make up other pictures, paste the turtles on the page with appropriate commands for the event onClick.

Download the Project

You can download an example of the finished project by clicking here.

 
   
  back to top