Skip to content
KinPilot™Learn & Explore
Menu

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.

D34 visual explanationAn exact-color fill starts inside the dark outline and follows edge-sharing white pixels. The boundary is closed. Diagonal contact does not count in this model.Color 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 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.

A click in the central white square fills the connected interior; the optional gap gives matching pixels a route outside.

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
← Grades 3–5 topics