When you open KTurtle,
the turtle is in the middle of the canvas by default.
Let us start by getting the turtle to move.
The turtle can do three types of moves:
it can move forwards and backwards
it can turn left and right; and
it can go (or jump) directly to a position on the screen.
Let us go through a simple example.
In your editor, type the following commands:
reset
forward 100
turnleft 120
forward 100
turnleft 120
forward 100
turnleft 120
Also, note that the color of the code changes as we type it.
This feature is called the highlighting –
different types of commands are highlighted differently,
which makes it easier to read large blocks of code.
I am now clicking on run to execute the code
I will choose the Slower option so that we understand what commands are being executed.
The reset command sets the turtle to the default position.
The forward 100 command instructs the turtle to move forward by 100 pixels.
The turnleft 120 instructs the turtle to turn to the left ,anti-clockwise by 120 degrees.
Note that these two commands are repeated three times and a triangle is drawn.
Lets look at another example and also how to beautify our canvas:
We will now draw a triangle using a repeat command
A Simple Example: To draw a triangle
Type the following commands in the editor:
reset
canvassize 200,200
canvascolor 112,179,0
pencolor 0,0,255
penwidth 2
repeat 3 {
forward 100
turnleft 120
}
Click on Run now.
I have selected the slower option here again to run the commands.
The reset command sets the turtle to the default position.
The canvassize 200,200 sets the canvas width and height to 200 pixels
(here width=height, so the canvas is a square).
The canvascolor 0,255,0 makes the canvas green.
0,255,0 is a RGB (Red-Green-Blue)-Combination where only the green value is set to 255 (fully on)
and the others are set to 0 (fully off) ,
which results in the canvas being in green color.
The pencolor 0,0,255 sets the color of the pen to blue
(RGB combination where black value is set to 255).
The penwidth 2 sets the the width (i.e. the size) of the pen to 3 pixels.
The repeat command is followed by a number
and a list of commands within curly brackets.
This repeats the commands within the curly brackets the specified number of times.
Here the commands forward 100 and turnleft 120 are within curly brackets
and the repeat command is followed by the number 3 (because a triangle has 3 sides).
These commands are run 3 times in a loop
and all the 3 sides of the triangle are drawn.
|