INTRODUCTION |
Programming means giving a machine commands in order to control it. The first such machine that you will control is a small turtle on the screen, which we simply call turtle. What can this turtle do and what do you have to know in order to control it? Turtle commands are written in English and are always followed by a pair of parentheses, which may contain further details about the respective command. Even if no further information is The turtle can move within its window and draw a trail, but before it can get going, you must first instruct the computer to create such a turtle. You can do this with the command |
YOUR FIRST PROGRAM |
from gturtle import * makeTurtle() forward(141) left(135) forward(100) left(90) forward(100)
|
MEMO |
At the beginning of each turtle program you must first load the turtle module, and then create a new turtle: from gturtle import * makeTurtle() Afterwards, you can give any amount of commands to the turtle. The three commands that the turtle surely understands are:
|
YOUR OWN TURTLE IMAGE |
from gturtle import * makeTurtle("sprites/beetle.gif") forward(100) dot(20) back(100) right(90) forward(100) dot(20) back(100) right(90) forward(100) dot(20) back(100) right(90) forward(100) dot(20) back(100) right(90)
|
MEMO |
If you want to use a different image for the turtle, as seen in the above example, you must first create an icon with an image editor. Normally, turtle images have a size of 32x32 pixels and a transparent background and are typically in GIF or PNG format. The image file should be stored in the subfolder sprites of the same directory in which your program is located. In the above program you are using the new command back(), with which the turtle moves backwards, as well as dot(), with which the turtle draws a filled circle, the radius of which you can specify (in pixels). |
EXERCISES |
|