H20-SectionHandout4

H20-SectionHandout4 - CS106B Handout #20 Winter 07-08...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS106B Handout #20 Winter 07-08 February 4, 2008 Section Handout #4 Problem 1: Filling a Region Most drawing programs for personal computers make it possible to fill an enclosed region on the screen with a solid color. Typically, you invoke this operation by selecting a paint-bucket tool and then clicking the mouse, with the cursor somewhere in your drawing. When you do, the paint spreads to every part of the picture it can reach without going through a line. For example, suppose you have just drawn the following picture of a house: If you select the paint bucket and click inside the door, the drawing program fills the area bounded by the door frame as shown at the left side of the following diagram. If you instead click somewhere on the front wall of the house, the program fills the entire wall space except for the windows and doors, as shown on the right: In order to understand how this process works, it is important to understand that the screen of the computer is actually broken down into an array of tiny dots called pixels. On a monochrome display, pixels can be either white or black. The paint-fill operation consists of painting black the starting pixel (i.e., the pixel you click while using the paint- bucket tool) along with any pixels connected to that starting point by an unbroken chain of white pixels. Thus, the patterns of pixels on the screen representing the preceding two diagrams would look as shown below: Write a program that simulates the operation of the paint-bucket tool. To simplify the problem, assume that you have access to the enumerated type enum pixelStateT { White, Black }; The type pointT is defined as follows: struct pointT { int row, col; }; A Grid<pixelStateT> will be used to represent the screen.will be used to represent the screen....
View Full Document

Page1 / 5

H20-SectionHandout4 - CS106B Handout #20 Winter 07-08...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online