Unformatted text preview:

COMP 14, Fall 2000Assignment 9: Turtle Graphics (Last One!)Assigned: Tue Nov 21, 2000ObjectivesPart 2COMP 14, Fall 2000 Assignment 9: Turtle Graphics (Last One!)Assigned: Tue Nov 21, 2000 Part 1 Submission Date: Fri Dec 1, 5pm. (There will be extra lab hours on Thu night (Nov 30) 7-11pm).Part 2 Submission Date: Thu Dec 7, before class starts.Objectives - Create and manipulate graphical shapes.- Use the MVC (Model-View-Controller) architecture.- Use the switch statement and inheritance. - Use a Java toolkit (AWT or Swing).In this assignment, you will create a turtle editor. In part 1, you will use ObjectEditor to display and manipulate the turtle, and in part 2 you will use standard Java libraries and the MVC architecture to do so. Inyour implementation, you should use switch statements and inheritance wherever you can. A sample (applet) implementation of part 2 with extra credit is linked from the assignments page. Its URL is http://www.cs.unc.edu/~dewan/comp14/f00/assignments/turtle/ATurtleAppletComposer.htm. Try it before you begin the assignment. It will work only if your autoexec file has put shapes.jar in the CLASSPATH. Access the applet from the computer on which you did the first assignment.Part 1 Create a turtle editor that allows a user to move a turtle on the screen. This part includes a regular component and an extra credit component. The figure on the next page shows features of both components.Regular CreditAs shown in the figure, the “turtle” is represented by two adjacent, solid, circles, one for the body and another for the head. The head always points in the direction in which the turtle is pointing. The turtle can point in the north, south, east or west direction, and can move both forward and backward in the direction it is pointing. Initially, the turtle is pointing eastwards, as shown in the left window of the figure.The turtle should have one (instance) integer property, MoveDistance. In addition, it should provide thefollowing (instance) public parameter-less procedures: 1. rotate(): Rotate the turtle 90 degrees in the anti-clockwise direction.2. move(): Move the turtle the number of pixel units given by the MoveDistance property . Movement is in forward (backward) direction if the value of the property is positive (negative).As you saw in the first assignment, ObjectEditor creates a menu to invoke all public methods of an object (except the getter and setter methods, which are called implicitly when you edit the properties they define). The name of the menu is the class of the object. Use this menu to test these procedures. You are free to choose the sizes and colors of the body and head and the initial position of the turtle.One of the potentially messy tasks you have to worry about is rotating the turtle. It will be best to store the direction of the turtle as a positive number between 0 and 3.1Extra Credit 1. Allow users to draw lines by moving the turtle on the screen, telling the turtle to pick up or put down a pen as it moves (right window of the figure). A boolean property, PenDown, determines if the pen is upor down, as shown in the figure. Since the number of lines is variable, look at the section in chapter 13 on exposing dynamic indexed elements. 2. Add two new integer properties, StepSize and StepTime and the following instance public , parameter-less procedure:animationMove(): Like move(), this method moves the turtle the number of pixel units given bythe MoveDistance property. While move() essentially makes the turtle take one big step to its new position, this makes it take several small steps to its destination, animating the turtle as it moves. The size of the step, in pixels, is given by the property, StepSize, and the time to take a step is given by the property, StepTime. To implement animation, you will need to look at the sections on animation given in Chapter 12, which will probably not be covered in class or the exam. So do this part only if you have plenty of time to spare.These two extra credit features are independent in that you will get separate credit for each of them. 2Part 2For this part, you will no longer rely on ObjectEditor to display and manipulate the turtle, directly using Javalibraries. You can use the AWT or Swing library. The figure below shows both the regular and extra credit features for this part. Regular CreditMake a turtle model object out of the turtle object of part 1. You will make full points only if the class and interface of the former are subtypes of the class and interface of the latter. Next implement a view and controller for the turtle model that provide (a) a text field that allows the user to change the MoveDistance property of the turtle, and (b) buttons to invoke the move() and rotate() methods of the turtle. Also, provide a quit button to terminate the program.Implement a composer that creates two turtle editors for a turtle model simultaneously on the screen, as shown in the figure below. The controller and views of the editors should ensure that after each command that changes the turtle model, all of the views of the model are updated immediately. Creating two editors that are in sync should be trivial if you have followed the MVC architecture. Make sure the two editor windows are not located at the same position - otherwise you will see only one of them. You will need to read both chapters 14 and 15 to implement these features. The code for point history view and controller should serve as a template for the turtle model and view.Extra Credit1. Provide a way to create the two editors in an applet, as shown in the sample turtle implementation. This can be done even if you did not do any extra credit for part 1. For this feature, you need to create your composer class as a subclass of Applet. In the Applet version, be sure to comment out all console I/O code (println() , readString(), and so on) in your programs- otherwise the browser will give you an exception. Also, you will need to put all the class files (both for part 1 and 2) in the directory in which your HTML file is located. Applets will probably not be covered in class or the exam. How to create them is described in chapter 15.2. If you implemented line drawing in part 1, provide a check box to change the PenDown property. Look the discussion on checkboxes in Problem 8, chapter 15. 3. If you implemented animation in part 1, do the same for this part. Provide a button to invoke animationMove().If you


View Full Document

UNC-Chapel Hill COMP 14 - Assignment 9 - Turtle Graphics

Download Assignment 9 - Turtle Graphics
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Assignment 9 - Turtle Graphics and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment 9 - Turtle Graphics 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?