I'm trying to implement the simple boundary fill method (using 4 connected approach) for filling a rectangle. I did it as follows (code below), but the rectangle is not getting filled properly: it stops filling when it reaches the half portion of the rectangle.
But the same code works fine when trying to fill a circle. Can anyone help me to figure out the problem?
Thanks in advance
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
void boundfill(int xc, int yc, int r, int b) {
int cur;
cur = getpixel(xc, yc);
if (cur != b && cur != r) {
putpixel(xc, yc, r);
delay(1);
boundfill(xc + 1, yc, r, b);
boundfill(xc - 1, yc, r, b);
boundfill(xc, yc + 1, r, b);
boundfill(xc, yc - 1, r, b);
}
}
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "..\\bgi");
rectangle(100, 100, 300, 300);
boundfill(105, 105, 4, WHITE);
getch();
closegraph();
}
Output:
But when I use the following co-ordinates for rectangle, it is working fine. Given co-ordinates:
rectangle(50, 50, 100 ,100);
boundfill(55, 55, 4, WHITE);
For this the output is: