Graphic by Keith Ohlfs |
Patchwork Quilts
|
In this problem set, you will be writing Java methods that draw the sort of patchwork quilt patterns presented in lecture on Tuesday, September 30. The purpose of this assignment is to give you experience with using methods to implement divide-and-conquer problem solving techniques.
In particular, you are to write methods for drawing the following four quilts:
All four quilts can be decomposed in ways similar to the quilts presented in lecture. Before beginning this assignment, you may wish to review the structure of the patchwork.java program presented in lecture. You can download a copy of the patchwork folder via Fetch from the ~cs111/download directory on Nike.
When you are ready to begin the assignment, download the ps3 folder via Fetch from the ~cs111/download directory on Nike. Rename the downloaded folder to be username_quilts, where username is your Nike user name. This folder contains files quilts.java, quilts.html, and quilts.proj. You should rename all of these to be prepended with your username: username_quilts.java, username_quilts.html, username_quilts.proj. You will also need to rename the class within the username_quilts.java file to be username_quilts.
The file username_quilts.java contains a "skeleton" of the code for drawing the four quilts that you are to flesh out. This file contains a paint method for drawing the four quilts:
public void paint(Graphics g) { this.drawStripes16x16(g, Color.yellow, Color.red, 160, 0, 0); this.drawExplode16x16(g, 160, 200, 0); this.drawWeave16x16(g, Color.yellow, Color.black, Color.white, 160, 0, 200); this.drawDiagonals16x16(g, Color.red, Color.blue, Color.yellow, 160, 200, 200); }
The file also contains a "stub" method for drawing each of the four quilts. A stub method is one that allows the file to compile but does not have the correct behavior. For example, the stub method for drawStripes16x16 simply draws a quilt in which all patches are red:
public void drawStripes16x16 (Graphics g, Color c1, Color c2, int side, int x, int y) { // This is a stub definition that you should replace: this.draw16x16(g, Color.red, side, x, y); }
Your goal is to redefine each stub so that it draws the correct quilt. Of course, as in the patchwork.java file, each method for drawing a whole quilt will need to invoke auxiliary methods for drawing subparts of the quilt. You will need to define these auxiliary methods as well. The username_quilts.java file already contains helper methods for drawing 16x16, 8x8, 4,x4, 2x2, and 1x1 squares of uniform color; you should find these useful in writing your methods. Some of the stub methods include some comments about parameter usage; you should pay special attention to these comments.
Since the goal of the assignment is to show the power of methods for decomposing problems into parts, you should strive to make your method bodies contain only a few statements. In particular, you should not have a method that contains 256 statements! In fact, you should need no more than four statements in any method body, though you may use more statements than this if you find it necessary.
To submit your assignment, turn in your username_quilts folder into your ps3 drop folder on Nike. The problem set due date has been extended to 6pm on Tuesday, October 7, to account for the delay in the appearance of the problem set. You should turn in whatever you have at that time, even if some of your methods don't correcly draw the quilts. On the evening of Tuesday, October 7, a solution to this assignment will be made available so that you can use it to study for the exam on Thursday, October 9.