Lesson 2

Programming Our Turtle

Now that we can code commands for our turtle, let add some more “turtle specific” code.

On line 10, we will set the size of the pen our turtle will use.The pensize takes an integer which represents how many pixels wide we want the pen to be. Start with 2, this number can always be changed later on.

On line 11, we we will be choosing the color of that pen. The pencolor takes a string (a text contained in quotes), and has to match one of the possible colors the turtle knows. For now, use one of the following colors: blue, black,purple, red, teal, green, violet.

On Line 12, we will set the speed at which our turtle will move. Start with 2, this can always be changed later.

So far, we have set up all of the ‘variables’ that affect our pen. The Size, the Color, and the Speed. In the next step, we will program out turtle to move.

Making our Turtle Move


To move our turtle, we use a set of commands that our turtle recognizes.

turtley.forward() will move our turtle forward a certain number of pixels.

turtley.backwards() will move our turtle backwards

turtley.right() will move our turtle to the right

turtley.left will move it to the left.

Copy the code shown in the image, or create your own!

To test your code, look for “Run” on the top toolbar. Select “Run without Debugging.”

A pop-up window will appear, and show our Turtle following the instructions we coded. The turtle should draw a line wherever it goes.

To prevent the Turtle window from closing automatically, add done() to the very bottom of our code

Once we have drawn our lines, we will want to ‘erase’ it to set up for more drawings. On line 21 add the following code: turtley.clear()