Color+and+Procedures

LESSON #8 - Color and Procedures
Original lesson on color - 2009 Revision date - Fall 2017

Logo Color Commands quick reference ** Purpose: ** This lesson introduces Logo color commands, sub-procedures, and calling procedures. A Section of the Lesson Follows
 * Essential Questions: ** How can you add color to a Logo design? How can you store Logo code so it is saved from one work session to the next work session?

There are a number of Logo commands that can be used to change the boring black and white Logo environment into a colorful and pleasing environment. The fist half of this lesson will provide examples of the various color commands and individual color codes. I strongly recommend that you investigate (play) with these commands on your computer. The second half of this lesson will illustrate how to write the Logo code for a house design in a way that breaks down the scene into small chunks. These chunks of code will be placed in sub-procedures. The main “calling” procedure, that puts all the chunks together, will be called HOUSE. The color commands used in this lesson are specific to Terrapin Logo.

** New Commands: ** In Logo, the pen color can be modified with the **SETPC** command followed by a single integer, a text command, or an RBG sequence. The background color can be changed using the **SETBG** command. The interior of a shape can be changed using the **FILL** command. The fill command will use the turtle’s current pen color. If the pen color is red and you type fill, the interior of the shape will be red. The default pen color is black. To return the turtle to black, type **SETPC 0**.

It is important to use the **penup** (pu) and **pendown** (pd) commands when you do not want to have a line segment or a trail in the graphic. Also, recall that the pen width can be changed using the **SETW** command with an integer value between 1 and 99.

To color the interior of a shape, you must do the following: Practice the color commands by typing the following sequences in the listener window. Compare the graphics in figures 8.1 and 8.2 to your results.
 * 1) Move the turtle **to a location inside** the shape (I suggest a pen up, move, pen down sequence).
 * 2) Change to the desired pen color.
 * 3) Type FILL. You will probably **not** see the turtle icon, because it is the same color as the square. Use pen up (PU) and carefully move him out of the shape.

** Example 1: Red Square ** CS SETPC 5 REPEAT 4 [fd 100 rt 90] PU RT 45 FD 10 SETPC "red PD  FILL  SETBG "green PU

**Example 2: Yellow Hexagon** CS PD  SETBG 1 SETPC 0 SETW 10 REPEAT 6 [rt 60 fd 100] PU SETXY [15 0] SETPC [255 222 0] PD FILL

In most every Logo program, you can open a procedure editor by typing the words **TO NAME** in the listener window. Follow the steps below to create programs for Figures 8.1 and 8.2.
 * Lesson Eight – Task 1: **

 Type To redsquare in the listener window.  Type (or paste) the logo code above into the Program Editor.  Then type (or paste) the logo code for Example 1 in the program window. Click "Define".  To run the program, type redsquare in the listener window.
 * Figure 8.1 Red Square Program **



 Type To YellowHex listener window.  Type (or paste) the logo code above into the Program Editor. Click "Define".  To run the program, type YellowHex in the listener window.  Note that the program name is not case sensitive.
 * Figure 8.2 Yellow Hexagon Program **



Read through the sub-procedures and the main calling procedure for the house design. Type all of the procedures into Logo and compare the graphic to your results. Save your Logo workspace.
 * LESSON Eight - TASK 2: **