Skip to content

09. Filled Area Primitives - 2

Dated: 12-05-2025

Boundary Fill

We can find paint-scan function in common interactive paint packages.
Idea is to have a closed figure, then selecting a point within the figure with a color to fill.

The algorithm requires has parameters:

  • Coordinates of starting point
  • Fill color
  • Color of boundary

Algorithm

  • Check the pixel for boundary color
  • Check the pixel for fill color
  • Set the pixel in fill color
  • Run the process for neighbors

Flood Fill

Sometimes, we may want to replace the color of all connected pixels.
For this case, we just need something like if(getPixel(x, y).color == oldColor).

Neighbors

cs602_e_9_1.svg

Algorithm with 4 neighbors.

cs602_e_9_2.svg
Algorithm with 8 neighbors