flood fill with recursion
in
Programming Questions
•
5 months ago
just a while ago I came across recursive methods
no idea why I had not come across it before since they can be good
any way I tried to make a flood fill method what do you know I got stackover flow error
wonder if any of you guys have any ideas
I did look around online some suggested increasing the JVM stack size
but said that the best was to find a way to break out of th recursion
which is what I would like
below code more or less works except for large areas
- color old= color(255);
- void setup()
- {
- size(500,500);
- background(255);
- strokeWeight(5);
- for(int i=0; i<30;i++)
- {
- line(random(height),0,0,random(width));
- }
- }
-
- void draw()
- {
- }
-
- void mousePressed(){
- old=get(mouseX, mouseY);
- Fill(mouseX,mouseY,old, color(random(200,255),255,200));
- }
-
- void Fill(int x,int y,color oldColor,color newColor){
- if(get(x,y)!= oldColor)
- return;
- //&&x>height&&y>width&&x<0&&y<0
- set(x,y,newColor);
- Fill(x + 1, y, oldColor, newColor);
- Fill(x - 1, y, oldColor, newColor);
- Fill(x, y + 1, oldColor, newColor);
- Fill(x, y - 1, oldColor, newColor);
- }
1