Flood fill is an algorithm that determines connected regions in an array. It's used in the fill tool of paint programs, in Tetris implementations for determing what falls and what doesn't, and in Puyo Puyo implementations for determining what pieces are cleared.
Flood fill takes four parameters: seed x, seed y, source color, and destination color.
- Look to the left of the current element for more elements that match the source color.
- Look to the right of the current element for more elements that match the source color.
- Fill this horizontal line with the destination color.
- For each element above or below (or in 3D, in front of or behind) an element in the horizontal line that matches the source color, run flood fill on that element.
See this algorithm implemented in C with GDK.