1 / 8

The “Flood Fill” Algorithm

The “Flood Fill” Algorithm. A recursive graphics algorithm used to fill in irregular-shaped regions with a solid color. Region Boundaries. We often want to “color” regions which are defined by an irregular-shaped boundary

tcrocker
Download Presentation

The “Flood Fill” Algorithm

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The “Flood Fill” Algorithm A recursive graphics algorithm used to fill in irregular-shaped regions with a solid color

  2. Region Boundaries • We often want to “color” regions which are defined by an irregular-shaped boundary • Our earlier “scanline-fill” algorithm worked well for regions with boundaries defined by straight line-segments, or by circular arcs • But more complicated regions could lead to programming difficulties if the scanline approach is taken

  3. An irregular region

  4. Alternative: simple recursion • A “recursive” approach may be simpler • It works by successively reducing a very complicated problem to one that is just a little bit easier to solve • We apply that idea to a graphics problem: coloring the interior of an irregular region

  5. A flood-fill algorithm void fill( int x, int y, int interiorcolor, int newcolor ) { if ( get_pixel( x, y ) == interiorcolor ) { put_pixel( x, y, newcolor ); fill( x -1, y, interiorcolor, newcolor ); fill( x+1, y, interiorcolor, newcolor ); fill( x, y -1, interiorcolor, newcolor ); fill( x, y+1, interiorcolor, newcolor ); } }

  6. Demonstration setup • We need a way to create irregular regions • We will do it by using “bezier curves” • We subdivide the viewpoint into quadrants • We form a bezier curve in each quadrant • These bezier curves will connect together • First and last control-points are mid-axes • Other control-points are randomly chosen

  7. Four bezier curves viewport

  8. Demo-program • Our ‘flood.cpp’ demo implements this idea • You can find it on our course website • It does all of its drawing on page 0 • But you might want to draw to page 1, and then afterward copy from page 1 to page 0 • That avoids your user seeing the effects of a “slow” drawing operation in-progress

More Related