CS 140 - Lab 14 Instructions

In this lab we are going to modify and extend our random walk simulation.

Objectives

  1. Experiment with the random walk simulation.
  2. Experiment with new turtle object methods getXPos(), getYPos(), and moveTo(x,y).
  3. Experiment with new World object methods getWidth(), getHeight().

Method

Part I - Experimenting with Random Walk

  1. You can change the color of the pen a turtle uses by calling the setPenColor method on a turtle object. This method takes a color as a parameter. Set the color of the pen to yellow and rerun the random walk. Hint: call this method before the loop right after you construct the turtle object.
  2. Set the color of the pen to a random color. Hint: generate three random integers between 0 and 255.
  3. Currently the turtle can turn up to 360 degrees before each step. Turning 270 degrees clockwise is the same as turning ___________________ counter clockwise?
  4. Rather than turning between 0 and 360 degrees, limit the angle a turtle can turn to the right or left to 45 degrees. Hint one: generate a random number between -45 and 45. Hint 2: To do hint one generate a random number between 0 and 90 and subtract _________.
  5. Change the turtle's pen color to a random color every time it moves forward.
  6. Add a method named circle to the file Turtle.java. Have the turtle go in a circle by going forward ten pixels and turning twenty degrees. Use a for-loop and figure out how many times it needs to go around.
  7. Now from your main method call the circle method every 10th step the turtle takes. That is, when the loop variable i is divisible by ten make the turtle go in a circle.

Extra Credit

There is a Turtle method drop that takes a Picture object and places it on the world at the turtle's current location. Construct a new turtle and world object and have the turtle move in a circle dropping a picture along the way.


© Ed Harcourt