Grades 3–5 · Computing
How does a paint bucket find the inside of a shape?
One click with a digital paint bucket can color a whole enclosed shape. The computer does not need to recognize a house or flower. It follows connections between the little picture squares called pixels.
In the diagramColor spreads through matching neighborsWhite squares share edgesOrange dot:starting clickBoundary closed9 squares filledSame color aloneis not enough.The rule also needs a connected route.
In this simplified picture, the click starts at a white square. The tool checks the squares sharing its edges. Matching white neighbors join the fill, and their neighbors are checked in turn. Squares that have already been visited are not processed endlessly.
The dark outline has a different color, so this exact-color search cannot cross it. With the boundary closed, only the nine white squares inside become blue. The white squares outside remain unchanged even though they started with the same color.
A one-square gap changes the result. It gives the search a matching route to the outside, so that area fills too. Real paint tools may allow similar colors or close small gaps, but connectedness explains this basic behavior.
About this explanation
Starting knowledge: Understand a picture as small pixel squares and identify edge-sharing neighbors.
Sources
- GIMP — Bucket Fill