An advanced, interactive web-based visualizer for the Boundary Fill Algorithm. This project provides a real-time simulation of how seed-fill algorithms work in a pixel-based grid, commonly used in computer graphics and digital image processing.
The Boundary Fill Algorithm is a fundamental recursive procedure used in computer graphics to fill a connected region of a specific color, bounded by a different color. It is categorized as a "seed-fill" algorithm, where the process initiates from a starting coordinate
In this implementation, we utilize a 4-connected adjacency model. This means that for any given pixel
- Right:
$(x+1, y)$ - Left:
$(x-1, y)$ - Up:
$(x, y+1)$ - Down:
$(x, y-1)$
The algorithm can be defined as a function
void boundaryFill(int x, int y, int fill_color, int boundary_color) {
// Retrieve the color of the current pixel
int current_color = getPixelColor(x, y);
// Termination condition: pixel is boundary or already filled
if (current_color != boundary_color && current_color != fill_color) {
// Color the current pixel
setPixelColor(x, y, fill_color);
// Recurse to 4-connected neighbors
boundaryFill(x + 1, y, fill_color, boundary_color);
boundaryFill(x - 1, y, fill_color, boundary_color);
boundaryFill(x, y + 1, fill_color, boundary_color);
boundaryFill(x, y - 1, fill_color, boundary_color);
}
}The following animation demonstrates the recursive nature of the algorithm as it traverses a bounded region:
-
Dynamic Grid Generation: Configure custom
$M \times N$ pixel matrices. - Manual Boundary Definition: Interactive "draw" mode to create arbitrary shapes.
-
Async Execution: Real-time animation of the recursion stack using
async/awaitand time delays. - State Persistence: Visual indicators for start pixels, boundaries, and processed regions.
A modern web browser with JavaScript enabled.
- Clone this repository:
git clone https://github.com/adhishagc/boundaryfill-algorithm-simulation-sample-code.git
- Open
index.htmlin your browser.
- Define Grid: Input dimensions and click Generate Grid.
- Draw Boundaries: Click and drag on the grid to define the shape boundaries.
- Select Seed: Enable Pick Seed Point and click inside the bounded area.
- Execute: Click Run Algorithm to visualize the recursive fill.
Seed filling algorithms are computationally expensive for large regions due to the depth of the recursion stack. Modern implementations often optimize this using scanline-fill techniques or iterative stack-based approaches to prevent stack overflow errors in high-resolution buffers.
Optimized for Computer Science Education and SEO Visibility.

