This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Implementing flood fill Paint programs often offer a flood fill function. When you click a point, the entire region around the point is painted with your selected color. How does this work? Bitmaps A bitmap is a two-dimensional array, where each entry corresponds to the color of one pixel . A pixel (“picture element”) is a little square on the screen. There are different ways to specify color (a typical way is to use 8 bits each for red, green, and blue intensity information, so 24 bits in total). We will assume that the color is an int . To compute the region containing the clicked pixel, we need to define which pixels are “neighbors”. We use the convention that pixels have four neighbors: up, down, left, and right. We do not consider the diagonally adjacent pixels as neighbors. The first algorithm - using recursion The first thing to perform flood filling is remembering the old color of the pixel to be painted. Pixels with the old color would be filled, and other pixels take a role of a boundary. Then we color the pixel, and we seethe old color would be filled, and other pixels take a role of a boundary....
View Full Document
- Fall '09
- Recursion, Call stack, Depth-first search, Articles with example pseudocode