2.1 Turtle Commands

We introduced 4 different Turtle commands back in Chapter 1. These commands barely begin to scratch the surface of what Turtle is capable of doing. While it will be a while before you are exposed to the entirety of what turtle is truly capable of, now is a good time to take a look at some of the other commands available to you.


2.2 - Tail Up and Down

The physical analogy used in this software system is that of a turtle placed inside of a pond. The turtle's tail has been dipped in some color, and whenever the turtle moves a trail of that color is left behind. Most of the time, this allows us to make some interesting looking images. However, there are times when we want to be able to move the turtle around without leaving that trail of color behind.

This is where the and blocks come in handy. They allow us to dictate when the turtle picks up its tail, or places the tail back into the pond. Consider the following program:

In this program, the first thing that happens is the command to pick the turtle's tail up. As such, any movement by the turtle will not leave a trail behind him. This means that all of the movement above will essentially be hidden from the user, resulting in the following output:

However, if we add the command to put the turtle's tail back down between the two moves:

Which will create the output:

Keep in mind that whenever we command the turtle to place its tail in a particular orientation, it will keep its tail there until another command to move the tail is executed. This means we do not need to put a command to pick up the tail before each movement we want to not have drawn.


2.3 - Move To

The Turtle's pond is setup as a traditional Cartesian coordinate system. The origin [location (0, 0)] is at the center of the screen. It also uses the standard x and y syntax. Look at the image below for an example of how the coordinate system works.

Turtle provides a mechanism for you to move to arbitrary locations in the Turtle pond. The block for that is . This block allows you to specify an arbitrary x and y location on the Turtle screen to move the turtle to. This does not affect anything else about the Turtle except for the position. Consider the following program:

This moves the Turtle intothe upper left hand corner of the screen (since X is negative, and Y is positive), then draws a line straight to the right, like so:


2.4 - Set Color

Up until now, the Turtle has always drawn a black line. However, with the block, we can modify the color that the turtle draws in. This block changes the color the turtle draws in permanently. Every drawn movement after this block will be drawn in the new color until a new set color block is encountered.


Execises

  1. Create a blockly program that draws an orange square (where each side is of size 100) centered around the origin.

  2. Create a blockly program which connects the ends of coordinate markers together using a green line. You can assume that the standard pond is 800 pixels wide by 600 pixels tall.

    Note: You could do this using forwards and turns, but it will be much easier using the move to block.

  3. Challenge
    Create a blockly program which creates a 3-dimensional cube as shown below. Note that this shape is simply two diamonds with lines connecting their corresponding vertices.