Summary: In this laboratory, you will experiment with turtle graphics, both reading and writing code.
a. In the interactions pane, create a new
300x200 image called world and show that image.
b. In the interactions pane, create three turtles
called tommy, tanya, and tucker.
All three turtles should be placed on world.
a. Teleport tucker to the center of your image and
determine experimentally what direction it faces.
b. Determine experimentally where tanya starts.
(All turtles face the same direction, so you can use that information in
figuring out the starting point.) Hint: You'll
probably want to use a larger brush so that it's easier to see where
she is.
c. Using tucker, draw a red rectangular box 10 pixels in
from the outside edge of world. (Just draw the lines at
the border of the box; don't try to fill in the box.)
d. Without using turtle.teleport!,
write a series of instructions to move tommy to the
center of world. The turtle should “leave no
trace”. Make sure to put tommy's pen back down
when you reach the center.
a. Consider the following instructions. What do you think they do?
(turtle-forward! tommy 50) (turtle-turn! tommy 120) (turtle-forward! tommy 50) (turtle-turn! tommy 120) (turtle-forward! tommy 50)
b. Copy and paste those instructions into the definitions pane and click to test your hypothesis.
c. What do you expect to have happen if you click again?
d. Check your answer experimentally.
e. What do you expect to have happen if you click a third time?
f. Check your answer experimentally.
g. What do you expect to have happen if you click a fourth time?
h. Check your answer experimentally.
i. In the interactions pane, set tommy's brush
to "Circle Fuzzy (15)" and the color to yellow.
j. Click three more times.
k. In the interactions pane, set tommy's brush
to "Circle Fuzzy (11)" and the color to black.
l. Click three more times.
m. Using similar techniques, make this drawing a bit more interesting.
a. Clear the world, move tommy back to the middle, and
reset tommy's brush by
typing the following commands in the interactions pane.
>(image-select-all! world)>(image-clear-selection! world)>(image-select-nothing! world)>(context-update-displays!)>(turtle-teleport! tommy 150 100)>(turtle-face! tommy 0)>(turtle-set-brush! tommy "Circle (01)")>(turtle-set-color! tommy "black")
b. What do you expect to have happen if you add the following line to the end of the previous code (in the definitions pane) and then click three times?
(turtle-turn! tommy 120)
c. Check your answer experimentally.
d. What do you expect to happen if you add the following line to the end of the previous code (in the definitions pane) and then click a few times?
(turtle-turn! tommy 30)
e. Check your answer experimentally.
f. What do you expect to happen if you add the following line to the end of the previous code (in the definitions pane) and then click a few times?
(turtle-forward! tommy 10)
g. Check your answer experimentally.
h. How might you use the techniques we just explored to generate more complex images? Be prepared to share your answer with the class.
a. Clear the image and reset tommy, as in the previous
exercise. Also, delete all the commands in the
definitions pane.
b. Consider the following code.
(turtle-forward! tommy 50) (turtle-turn! tommy angle) (turtle-forward! tommy 50) (turtle-turn! tommy angle) (turtle-forward! tommy 50) (turtle-turn! tommy angle) (turtle-forward! tommy 50) (turtle-turn! tommy angle) (turtle-forward! tommy 50)
Suppose we defined angle as 72. What do you expect the
code to produce?
c. Check your answer experimentally. That is, add a definition
for angle to the definitions pane, cut-and-paste the
code after that definition in the definitions pane, and then click
.
d. What do you expect to happen if we click a few more times?
e. Check your answer experimentally.
f. Suppose we defined angle as 144, rather than 72.
What effect would this have on the drawing?
g. Check your answer experimentally.
h. Try a few other angles and see what kinds of images you can produce by repeatedly hitting . For example, you might try 45, 60, 75, and 150.
Write a series of instructions to have a turtle draw a spiral. (It's fine if the spiral is jagged.)
One technique for making six-pointed stars is to overlay two equilateral triangles. Using the instructions you've already seen for making equilateral triangles, write a series of instructions to make a six-pointed star.
In exercise 3, you learned that a few extra changes at the end of a drawing can lead to an attractive sequence of drawings. In exercise 4, you learned how to make a pentagon and a five-sided star. Make a few changes to the code for one of those two figures (or some other variant), similar to those we made in exercise 3, to generate an image you find visually appealing.