CG Assignment 1
CG Assignment 1
Title: Polygon filling using Boundary Fill and Flood Fill Algorithm.
Problem Statement: Write C++ program to draw a polygon and fill it with desired color using
Boundary Fill and Flood Fill Algorithm
Objectives:
To learn the concept of polygon drawing and polygon filling using Boundary Fill and Flood Fill
Algorithm
Theory:
Polygons
A polygon is a many sided figure. It can be generally thought of as a shape. A surface which is
closed and bounded by straight line segments is known as a Polygon. The shape is formed by
the line segments that are placed end to end to create a continuous closed path. Triangle is the
simplest form of polygon having three sides and three vertices. At least three line segments
should not be linear. The line segments of a polygon are called as the edges of the polygon (or
sides). The point of intersection of two edges is called its vertices.
Figure 1: Polygon
Polygon Filling
Filling a Polygon is the process of coloring every pixel that comes inside the Polygon region.
Polygon Filling Techniques:
1. Boundary Fill Method
2. Flood Fill Method
3. Scan – Line Fill Method
Boundary Fill Method
It is also known as the “Seed-Fill Method”. Initially, draw the Polygon boundaries. A Seed-Point
i.e. an arbitrary interior point is taken as the initial or the starting point. Test neighboring pixels to
determine whether they correspond to the boundary pixel. If not, paint them with the fill-color and
test their neighboring pixels, store neighbors in the stack. Continue until all pixels have been tested.
Boundary Fill Algorithm is recursive in nature. It takes an interior point(x, y), a fill color, and a
boundary color as the input. The algorithm starts by checking the color of (x, y). If its color is not
equal to the fill color and the boundary color, then it is painted with the fill color and the function
is called for all the neighbors of (x, y). If a point is found to be of fill color or of boundary color,
the function does not call its neighbors and returns. This process continues until all points up to
the boundary color for the region have been tested.
A considerable stack is used to store pixel information. Basically, it is of two types :
1. 4-Connected Seed Fill
2. 8-Connected Seed Fill
A point or seed which is inside the region is selected. This point is called a seed point. Then four
connected approaches or eight connected approaches are used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But this method is more
suitable for filling multiple color boundaries. When the boundary is of many colors and the interior
is to be filled with one color we use this algorithm.
In the fill algorithm, we start from a specified interior point (x, y) and reassign all pixel values that
are currently set to a given interior color with the desired color.
Conclusion:
Hence, we have studied how to draw and fill a polygon using Boundary Fill and Flood Fill
Algorithm.