| |||||||||
Flood fill, also called seed fill, is a recursive algorithm that determines connected regions in a multi-dimensional array. It is used in the "bucket" fill tool of paint programs to determine which part of a bitmap to fill with color, in Tetris implementations for determing what falls and what doesn't, and in Puyo Puyo and Magical Drop implementations for determining what pieces are cleared.
Flood fill takes three parameters: start element, source symbol, and destination symbol. It changes every element in the array that is connected to the start element and that contains the source symbol to the destination symbol. Normally, a helper function wraps around flood fill and initializes the source symbol from the symbol under the provided point.
Adapting the algorithm to use an additional array to store the shape of the region allows generalization to cover "fuzzy" flood filling, where an element can differ by up to a specified threshold from the source symbol, and the edges of the filled region blend somewhat smoothly with the not-filled region.