: Hi! : Can anyone get me the algorithm used for floodfill() in BGI graphics in C/C++. : Thanks in advance,Byeeee. : : :
The generic algorithm for floodfill is...
void floodfill(int x, int y, color back, color fill){ if(x<0 || x>maxX || y<0 || y>maxY || getPixel(x,y)!=back) return; setPixel(x,y,fill); floodfill(x+1,y); floodfill(x,y+1); floodfill(x-1,y); floodfill(x,y-1); //you can make this an 8-connected neighborhood by adding //the intermediate cases eg floodfill(x+1,y+1); }
The problem with this algorithm (the way it is now) is that it takes up massive amounts of stack space for large areas. In DOS this algorithm will definitely cause a stack overflow for large areas.
Have fun playing around with it, you can definitely minimize the stack space. It will still overflow for large areas, but it will be able do larger areas than it current can. Experiment. See if you can make it more efficient.
"We can't do nothing and think someone else will make it right." -Kyoto Now, Bad Religion
Hi Darius, I have already tried that algorithm. Works fine for small areas but large areas create problem. How do I manipulate with the stack size? I use Turbo C++ compiler. Also why doesn't the same thing happen when I fill in larger areas using the in-built fllodfill() function. Bi, Ritesh
: : Hi! : : Can anyone get me the algorithm used for floodfill() in BGI graphics in C/C++. : : Thanks in advance,Byeeee. : : : : : : : : The generic algorithm for floodfill is... : : void floodfill(int x, int y, color back, color fill){ : if(x<0 || x>maxX || y<0 || y>maxY || getPixel(x,y)!=back) return; : setPixel(x,y,fill); : floodfill(x+1,y); : floodfill(x,y+1); : floodfill(x-1,y); : floodfill(x,y-1); : //you can make this an 8-connected neighborhood by adding : //the intermediate cases eg floodfill(x+1,y+1); : } : : The problem with this algorithm (the way it is now) is that it takes up massive amounts of stack space for large areas. In DOS this algorithm will definitely cause a stack overflow for large areas. : : Have fun playing around with it, you can definitely minimize the stack space. It will still overflow for large areas, but it will be able do larger areas than it current can. Experiment. See if you can make it more efficient. : : "We can't do nothing and think someone else will make it right." : -Kyoto Now, Bad Religion : :
Comments
: Can anyone get me the algorithm used for floodfill() in BGI graphics in C/C++.
: Thanks in advance,Byeeee.
:
:
:
The generic algorithm for floodfill is...
void floodfill(int x, int y, color back, color fill){
if(x<0 || x>maxX || y<0 || y>maxY || getPixel(x,y)!=back) return;
setPixel(x,y,fill);
floodfill(x+1,y);
floodfill(x,y+1);
floodfill(x-1,y);
floodfill(x,y-1);
//you can make this an 8-connected neighborhood by adding
//the intermediate cases eg floodfill(x+1,y+1);
}
The problem with this algorithm (the way it is now) is that it takes up massive amounts of stack space for large areas. In DOS this algorithm will definitely cause a stack overflow for large areas.
Have fun playing around with it, you can definitely minimize the stack space. It will still overflow for large areas, but it will be able do larger areas than it current can. Experiment. See if you can make it more efficient.
"We can't do nothing and think someone else will make it right."
-Kyoto Now, Bad Religion
I have already tried that algorithm. Works fine for small areas but large areas create problem. How do I manipulate with the stack size? I use Turbo C++ compiler. Also why doesn't the same thing happen when I fill in larger areas using the in-built fllodfill() function.
Bi,
Ritesh
: : Hi!
: : Can anyone get me the algorithm used for floodfill() in BGI graphics in C/C++.
: : Thanks in advance,Byeeee.
: :
: :
: :
:
: The generic algorithm for floodfill is...
:
: void floodfill(int x, int y, color back, color fill){
: if(x<0 || x>maxX || y<0 || y>maxY || getPixel(x,y)!=back) return;
: setPixel(x,y,fill);
: floodfill(x+1,y);
: floodfill(x,y+1);
: floodfill(x-1,y);
: floodfill(x,y-1);
: //you can make this an 8-connected neighborhood by adding
: //the intermediate cases eg floodfill(x+1,y+1);
: }
:
: The problem with this algorithm (the way it is now) is that it takes up massive amounts of stack space for large areas. In DOS this algorithm will definitely cause a stack overflow for large areas.
:
: Have fun playing around with it, you can definitely minimize the stack space. It will still overflow for large areas, but it will be able do larger areas than it current can. Experiment. See if you can make it more efficient.
:
: "We can't do nothing and think someone else will make it right."
: -Kyoto Now, Bad Religion
:
: