Change Contents of the Bubble
View this PageEdit this PageUploads to this PageHistory of this PageHomeRecent ChangesSearchHelp Guide

Midterm exam 1 review Sp2006: Make Turtle Boxes

Questions, comments, concerns, answers, concerns about answers?
(Back to Midterm Exam 1 Review Sp2006)


Looks like the little box's corner is in the middle (where the turtle starts) so...
public class MyTurtlePicture {
  
  public static void main(String [] args) {
    
    //FileChooser.setMediaPath("D:/cs1316/MediaSources/");
    Picture canvas = new Picture(600,600);
    Turtle jenny = new Turtle(canvas);
    //Picture lilTurtle = new Picture(FileChooser.getMediaPath("Turtle.jpg"));
    
    for (int i=0; i <=4; i++)
    {
      jenny.forward(100); //Starts facing up
      jenny.turnRight();
    }
    //Ends at start
    jenny.penUp();
    jenny.moveTo(jenny.getXPos()-50,jenny.getYPos()+50); //Move 50 left and 50 down
    jenny.setHeading(0);
    jenny.penDown();
    
    for (int i=0; i <=4; i++)
    {
      jenny.forward(200); //Starts facing up
      jenny.turnRight();
    }
    canvas.show();
  }
  
}

Yeah. Just used 2 loops. Manabu suggested a 'third box' approach that, in retrospect, seems a lot cooler.
Oh well.

So if I were to make the large box first, could I turn the turtle at a 45 degree angle and have it move forward to start making a smaller box.

Please put your statement in Java code form

if (I.make(box.larger())) {I.turn(turtle.turn(45)); turtle.forward(box.smaller());}? Is that what you were looking for? :-) (Sorry, just being a smart-aleck...) Mark Guzdial



Link to this Page