## COM 1370 Computer Graphics - Summer 2001 - Assignment 2

### ASSIGNMENT DUE ELECTRONICALLY BY MIDNIGHT, THURSDAY JULY 5th

#### Updated Saturday 6/30/2001

Your grade: Doing Part 1 tolerably will get you a 'C'. Doing the more difficult parts and doing them well can earn you up to an 'A'.

(repeating) This assignment is due electronically by the midnight on Thursday, July 5th (by the end of that day). Remember, turn in whatever you have done by that time.

Assignment #2 - earlier post. Preview of fat pixel interactive rectangle drawing (by Prof. Futrelle, 6/25/01). This combines the line drawing applet of Dori Smith with the fat pixel code from Assignment #1. Here's her source code for the line drawing applet. You will be required to recreate the rectangle drawing plus filling the interior using flood fill. The harder portion will involve reducing the redrawing by only redrawing when the mouse moves at least a full fat pixel. The full assignment will be posted soon.

### Assignment 2 itself:

Assignment 2, Part 1: Starting from Smith's listing ( here's a local copy), change her paint method to draw a fat pixel rectangle and also fill it each time it's redrawn. Here are some suggestions as to how to proceed, some based on the demo applet that I posted for you:

• Instead of g.drawLine() as in Smith's code, I made four calls to two functions I defined, drawFatHLine(Graphics,int x, int y, int x1) to draw a horizontal line at level y from x to x, and a similar drawFatVLine() method for a vertical line. In my case I used Math.min() and Math.max() inside these two functions to get the coordinates in low to high value order so the loops could always iterate using the ++ operator. That's why you can pull the rectangle out to the right or left or up or down and it still draws correctly.

• To handle the filling, you'll need to create an 2D array in your class that's large enough to include the fat pixels in the entire drawing area (500x500 pixels, but you can change that or the dimensions and/or size of your grid to some other reasonable value). If you make it a bit too large the browser will clip the drawing for you. In this int (or byte or short) array, you can use values such as 0 for unchecked, 1 for stacked 2 for filled and 3 for border.

• As part of your paint() function you need to create a flood fill() function which is passed your Graphics context as well as a start point in your array to start filling from.

• To do the fill, fill the current point by drawing the appropriate fat pixel, marking this in your array, and stacking any further points that need to be worked on. Keep looping (with a while()) until the stack is empty. Here's are links to a PointStack class I've written for you that will allow you to construct, push, pop, and check for empty for a stack of Point objects. (PointStack links: source code and Javadoc documentation). You can compile and run its test. Once it's compiled it will link properly into your code that uses it -- everything should be in the same directory.

• PointStack uses the Vector class, which you should be getting familiar with for future work. The Vector API is here, for Java 1.1.

Assignment 2, Part 2 (a tiny bit harder): Make the border and fill colors the same so that you're dragging a uniformly colored rectangle.

Assignment 2, Part 3 (Harder): Change the your algorithm so the repainting is only done when the mouse is moved far enough to enter a new fat pixel region. This should make it much smoother. You'll have to remember the current fat pixel position to compare with the mouse each time the mouse drag event occurs.

Assignment 2, Part 4 (Hardest): Replace the rectangle by a triangle with a fixed vertical edge such that dragging the mouse moves the third vertex, and fill it dynamically with the same fill() code (shape shouldn't matter!). This should also only redraw when a full fat pixel is traversed by the mouse. Hint: Whenever the mouse is to the right of the vertical line scan on the proper side of the vertical edge to see if there is any pixel that's unfilled in the interior. Fill in a different color than the border so you can be very sure what's getting done. You could start by writing it so it only works when the drag is to the right; that in itself would be an accomplishment.

See the page on electronic handins for the correct way to set up your directories and files for your electronic handins.