Boundary Fill Algorithm in C and C++

Boundary Fill Algorithm in C and C++

The Boundary Fill algorithm is used in computer graphics to fill a closed area with a specified color. It starts from a seed point and fills neighboring points until a boundary color is encountered. The algorithm is recursive in nature.

Boundary Fill and Flood Fill algorithm

The Boundary Fill and Flood Fill algorithm share several similarities:

  • Objective: Both algorithms are used in computer graphics to fill enclosed areas with designated colors.
  • Starting Point: They both start from a seed point within the region to be filled.
  • Coloring Process: Both algorithms iteratively change pixel colors based on specified conditions.
  • Neighbor Exploration: They examine neighboring pixels to determine whether they should be filled or stopped.
  • Recursive Approach: Both algorithms often employ a recursive approach to propagate color changes.
  • Boundary Constraint: Both algorithms stop when encountering a boundary color, preventing them from overflowing into neighboring regions.
  • Connected Regions: They effectively handle areas with gaps or inner boundaries by treating the enclosed region as a single entity.
  • Used in Graphics: Both algorithms play crucial roles in image editing, area coloring, and graphics rendering tasks.

While they serve similar purposes, the Boundary Fill algorithm focuses on filling a region up to its boundary, while the Flood Fill algorithm aims to fill connected regions until encountering a boundary color.

Boundary Fill Algorithm Program in C

Program Explanation

The program uses the graphics library to create a graphics window.

initgraph(&gd, &gm, “C:\\Turboc3\\BGI”); initializes the graphics mode.

circle(x,y,radius); draws a circle on the screen.

boundaryFill(x, y, 6, 15); initiates the boundary fill algorithm at the point (100, 100) with fill color 6 and boundary color 15.

The boundaryFill function is a recursive function:

It checks if the current pixel is not the boundary color or the fill color.

If the condition is met, it changes the pixel color to the fill color and then recursively calls itself on neighboring pixels.

getch(); waits for a key press to exit the program.

closegraph(); closes the graphics mode.

Output

Boundary Fill Algorithm

Boundary Fill Algorithm Program in C++

 

 

 

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top