



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Instructions for writing java procedures to draw shapes such as bouncing balls, spirals, polygons, and radiating lines using the turtle class in a jframe. The document also includes information on classes turtle, color, and hsv, as well as methods like movetocenter(), drawpolygon(), and koch. Students are expected to write and test the procedures given in the document.
Typology: Assignments
1 / 6
This page cannot be seen from the preview
Don't miss anything!




Assignment A5 CS1110 Fall 2008 See CMS for deadline This assignment introduces you to graphics. You will write procedures that draw interesting designs, bouncing balls, and a recursive design in a JFrame. You may work with one other person. If you do so, form your group on the CMS WELL BEFORE YOU SUBMIT YOUR FILES. Remember, partners should work together and not independently. You need not use a JUnit testing class. You will (partly) be looking at visual output (graphics) to determine correctnesss. Please keep track of the time you spend on this assignment. You will be asked to put it in a comment at the top of file A5.java. To save time and effort, we give you complete specifications of most of the methods you write. Please study them carefully. Note how precise and thorough they are. You should aim for this quality of specification when you write your own specifications. At the end of this document, we tell you what to submit. Download file A5.zip, unzip it, and put everything in it into a new directory. It contains:
at angle ang. Call pause(p) to pause execution for p milliseconds. Judicious use of this method will allow you to watch something being drawn in slow motion. Class A5.java contains procedure drawTwoLines to show you how graphics works. After compiling class A5, in DrJava's interaction pane, create an instance of class A5 and execute a call on drawTwoLines. A JFrame should be created and two lines should be drawn on it. Notice how the body of the procedure saves the initial color of the pen and ends by changing the pen back to its initial color. Generally, methods will attempt to leave things the way they were when they started, and this indicates how to do that. In the interactions pane (or in a method in class A5), draw some lines, rectangles, circles, etc, to familiarize yourself with class Turtle. After that, perform the tasks given below. Task 1. Complete function A5.toString. Follow the instructions given in the function itself. You will see why in Task 2. Here is an example of what our toString function produces, and yours should be similar: pos. (250, 250), facing 0.0 degrees, color java.awt.Color[r=0,g=0,b=0], pen down. Your output does not have to be precisely like this, but it should contain the same information, and in this order. Note: class Color has its own toString function. Task 2. Complete procedure drawRedTriangle. Then follow the instructions in the comment in the body to learn about rounding errors when using type double and why they don't really matter here. Note that the comment asks you to put some information at the topf of file A5.java (as a comment). Task 3. Complete drawRedHex to draw a red hexagon, as shown to the right of this paragraph. It should call procedure drawRedTriangle 6 times. Some lines will be drawn twice, but that is OK. Of course, when the procedure call terminates, the turtle's properties (position, angle, pen color, and whether the pen is up or down) should be the same as when the procedure call began. The procedure should draw the shape at the turtle's current position and at the turtle's current angle. Don't move the turtle before beginning. Also, note that THIS PROCEDURE DOESN'T HAVE TO DRAW ANY EXTRA LINES OR JUMP AROUND AT ALL. Just use calls on drawRedTriangle and addAngle. Task 4. Do TWO (repeat, 2) of 4A, 4B, or 4C. After you have completed the assignment, if you are interested, do the other one! It is fun, seeing how easy it is to do these neat things. Task 4A: Draw a spiral. The first picture to the right is done by drawing 10 lines. The first line has length 5; the second, 10; the third, 15, etc. After each line, 90 degrees is added to the angle. The second diagram to the right shows a similar spiral but with 75 degrees added to the angle after each line. Complete procedure spiral. When you first test your method, use 5 for d and 0 for sec. Try different angles, like 90 degrees, 92 degrees, 88 degrees, etc. You can also use msec = 500 or msec =1000 (which is 1 second) in order to see the lines drawn one at a time. You will be amazed at what method spiral does. Find out by trying these calls, assuming that x is an instance of A5. Use procedure moveToCenter() to erase the panel and place the turtle in the middle before
In this task 6, your job is to write a procedure that draws a recursive graphical design. You can choose from a few alternatives given below. Before we begin, make careful note of these ground rules: