Goal: Change the direction of the car when it touches a colored wall.
Vocabulary: fd (forward), setsh (setshape), seth (setheading), forever
- Draw a car shape (or click the "Shapes", and copy and paste a car into a shape). Name it racecar1.
- Make a second car shape that is a mirror image of the first, and name it racecar2. (If you are using the online shapes, you may copy and paste the mirror image race car into a second car shape.)
If you have drawn your own race car, select and copy the closed shape, then click once on another closed shape and paste (select Edit -> Paste or ctrl-V/command-V). In the Shape Editor, click the small "horse heads" button to flip to the mirror image, name the shape, and close it.
- Draw a background with two walls. Fill the left wall with a shade of orange and the right wall with a shade of red.
- Hatch a turtle and place the racecar1 shape on it. Position it between the two walls.
- In the go procedure, seth 90 means: "No matter what direction you were already facing, face to the right." (We say it, "set heading 90" and the 90 means 90 degrees.)
- Forever means: "Launch a process that keeps doing the commands inside the brackets, over and over again." It works the same way as making a button and setting it to Forever. But we do not want to keep setting the heading to 90, because we want the car to move in both directions. That is why we set the heading once to get started, and then use forever to keep the turtle moving.
- Make a button with go instruction, and keep it set to Once. Whenever you use forever in a procedure, be sure that any button launching the procedure is set to Once. If you try to launch forever over and over again, the project will crash.
- Now we need to program two colors so that when the car hits one color, it will change shape and direction, and when it hits the other color, it will change shape and direction again, back to the way it started out. This way it can keep bouncing back and forth between the two colors.
Open the dialog box for the color red (right-click/ctrl-click on red and select Edit red). In the white space next to turtle, write:
rt 180 setsh "racecar2
Now open the dialog for the color orange. Next to turtle, write:
rt 180 setsh "racecar1
Rt 180 means: "Turn 180 degrees to face the opposite direction."
Setsh means "set shape." The word after the quotation mark is the name of a shape.
- Your car (turtle) is now ready to smash into walls!!
What happens if you change the number after fd?
What happens if you add the command wait 1 after the fd command inside the brackets?
What happens if you use different numbers after rt in the instructions for the colors?
On Your Own - Project Ideas
Use programmed colors to control a different sort of animation (such as a skater on a frozen pond).