CPS 4 Summer 2003 : Quiz 7


Name: Grader: Score:

Note: This quiz can be quite time consuming. For this quiz only, you may work with a partner.

For each question below, you will be asked to experiment with the code by changing the values given as parameters. Feel free to copy the code given into a Visual J++ project and watch it run.

Making Circles?

Consider the behavior given in CircleBehavior.java which moves a given shape around in a circular path (in fact, this implementation is similar to many of your own solutions). This behavior works well as named when the angle change given is small, e.g., less than ten degrees. However, it may trace a much different shape when the angle is larger.

Note: if you actually run this code, the path might be much more obvious if you replace the Step routine shown above by :

public void Step () { myTarget.Move(myVelocity); if (myCount >= 10) { myCount = 0; myVelocity.Turn(myAngleChange); } else myCount = myCount + 1; } and adding int myCount = 0; to the instance variables.
  1. What angle change value is necessary to pass to the constructor when creating a CircleBehavior to trace each of the following shapes:
  2. Even more interesting shapes are traced for an angle change between 121 and 239 degrees. What shapes are traced for the following angle changes:
  3. Another interesting affect occurs when the angle change given is between 240 and 359 degrees. What shapes are traced for the following angle changes:
  4. Finally, give this behavior a better name than CircleBehavior and make a general statement about the shapes traced by it based on the characteristics you have observed in the problems above. For example, 
  5. Modify the CircleBehavior so that it takes another parameter which determines how much to increase the speed of the vector each step, like the angle is increased each step. What effect does this have on the overall behavior?









Moving Circles

Consider the applet linked below which combines two behaviors you have seen or written previously by adding them both to a single shape. Run the applet for a variety of starting values for both MoveBehavior and CircleBehavior by changing only the parameters given them in the applet. To better understand the path traced out by the moving shape, the applet also adds a behavior that leaves a trail behind the moving shape.

  1. Make a general statement about the paths traced by the moving shape based on the characteristics you observe. For example,
  2. What happens when you add MoveBehavior twice to the same shape?








  3. What happens when you add the MoveBehavior and your modified CircleBehavior to the same shape?








  4. What happens when you add your modified CircleBehavior twice to the same shape?








Circles Around Circles

Consider the following applet which combines two instances of a behavior similar to the CircleBehavior above but defined more intuitively for making circles: in terms of a diameter, seconds to move around the circle, and direction to move around the circle. Again, by varying the values used to initialize these behaviors you will see that a single complex behavior can result from two very simple behaviors.

  1. What happens if the fixed circle is bigger than rolling one? smaller? equal? very close to equal?







  2. What happens if the pen moves more quickly than the rolling circle? more slowly? the same rate? very close to the same?








  3. What happens when the pen and the rolling circle both move counter-clockwise, i.e., in the positive direction? both clockwise, i.e., the negative direction? in opposite directions?








  4. What happens if you use the same initial values in for both circles? opposite values?









  5. Make a general statement about the paths traced by the pen based on the characteristics you observe. For example,

     

  6. Modify the Spirograph class above so that the rolling circle travels around the inside of the fixed circle rather than around the outside. (Hint: the changes should be very minor and only in code within the Spirograph class.) Does this allow you to draw different shapes than you could before?