To Implement Flood Fill Algorithm
To Implement Flood Fill Algorithm
Algorithm
Flood
Fill
Theory:
Flood fill, also called seed fill, is an algorithm that determines the area
that are connected to a given node in a multi-dimensional array. It is used
in the "bucket" fill tool of paint programs to determine which parts of a
bitmap to fill with color, and in puzzle games such as Puyo Puyo, Lumines,
Magical Drop, and some implementations of Tetris (but not Columns) for
determining which pieces are cleared.
The flood fill algorithm takes three parameters: a start node, a target
color, and a replacement color. The algorithm looks for all nodes in the
array which are connected to the start node by a path of the target color,
and changes them to the replacement color. There are many ways in
which the flood-fill algorithm can be structured, but they all make use of a
queue or stack data structure, explicitly or implicitly. One implicitly stackbased (recursive) flood-fill implementation (for a two-dimensional array)
goes as described below algorithm.
4-Connected Region
North
East
West
South
1 | Page
These are the pixel positions that are right, left above, and below the
current pixel. Areas filled by this method are called 4-connected. It is
called 4-connected because it is connected to 4 neighbouring regions of
the current pixel.
8-Connected Region:
Seed point
North
East
West
South
North-East
North-West
South-East
South-West
}
}
floodfill8
floodfill8
floodfill8
floodfill8
}
}
Conclusion:
It is used when an area defined with multiple color boundaries.
Flood fill instead of checking the boundary colour it checks the
interior colour (original polygon colour).
It can be implemented using 4connected or 8 connected region
filling.
3 | Page