PImage img; void setup(){ img = loadImage("testimage.png"); image(img, 0, 0); size(1000, 1000); } void draw(){ } int visited[] = new int[100000]; int vcount = 0; void floodFill(int x, int y){ img.loadPixels(); visited[0] = x + y * width; vcount = 1; while(vcount > 0){ vcount--; int curr = visited[vcount]; img.pixels[curr] = color(0, 255, 0); if(curr+1 < img.width*img.height && green(img.pixels[curr + 1]) < 128){ visited[vcount] = curr+1; vcount++; } if(curr-1 >= 0 && green(img.pixels[curr - 1]) < 128){ visited[vcount] = curr-1; vcount++; } if(curr+width < img.width*img.height && green(img.pixels[curr + width]) < 128){ visited[vcount] = curr+width; vcount++; } if(curr-width >= 0 && green(img.pixels[curr - width]) < 128){ visited[vcount] = curr-width; vcount++; } } img.updatePixels(); image(img, 0, 0); } void mouseClicked(){ floodFill(mouseX, mouseY); }