CIT 594 Assignment 1: Flood Fill
CIT 594, Spring 2005

Purpose of this assignment:

General idea of the assignment:

Just about every painting program has a "flood fill" operation, typically represented as paint pouring out of a paint can. The purpose of the flood fill is to fill an irregular area, all of the same color, with a particular new color. For example:

Starting with this diagram (squares represent pixels), if the color is set to red and you click on the cell marked x... ...you will get this result. Notice that pixels along the boundary may meet along edges or only at the corners. Here is the same diagram again, with each of the six areas flood filled with a different color.

In the above example, the area to be filled was white, but in general it could be any color. To do a fill, you choose a single pixel and a new color. Make note of the original color of the chosen pixel; then set it to the new color. Any time you set the color of a pixel, then you must also set the color of any adjacent pixel (horizontally or vertically, but not diagonally) that has the original color.

Your assignment is to implement flood fill in two ways: recursively, and non-recursively. Create a two-dimensional array of Color, and implement a JApplet to display the array. You should be able to set individual (large) pixels on the display in order to draw an outline, and you should be able to choose one of the two fill methods (recursive and nonrecursive) to fill an area.

Here is some starter code, a JApplet composed of the two classes FloodFillApplet.java and ColorArrayComponent.java, for your use. Note that, if you use Eclipse to run the applet, you can resize the window easily.

Additional requirements:

Use Eclipse.

Due date:

Tuesday, January 18, before midnight.