PImage img; void setup() { img = loadImage("spiralthing.png"); image(img, 0, 0); size(1000, 1000); } void draw() { image(img, 0, 0); decount = 0; ff_continue(); } int tocheck[] = new int[100000]; int tcsize = 0; int decount = 0; void ff_continue() { while (tcsize > 0) { if (decount > 100) { break; } decount++; // Check to see if the last pixel in tocheck needs to be filled // If not, move on to the next pixel // If so, add the neighbors to tocheck if they need to be filled tcsize--; int curr = tocheck[tcsize]; if (red(img.pixels[curr]) < 128) { img.pixels[curr] = color(255, 100, 100); img.updatePixels(); if (curr - width > 0 && red(img.pixels[curr - width]) < 128 ) { tocheck[tcsize] = curr - width; tcsize++; } if (curr + width < (height * width) && red(img.pixels[curr + width]) < 128 ) { tocheck[tcsize] = curr + width; tcsize++; } if (curr - 1 > 0 && red(img.pixels[curr - 1]) < 128 ) { tocheck[tcsize] = curr - 1; tcsize++; } if (curr + 1 < width*height && red(img.pixels[curr + 1]) < 128 ) { tocheck[tcsize] = curr + 1; tcsize++; } } } img.updatePixels(); } void floodFill(int x, int y) { img.loadPixels(); int startpoint = x + y*width; tocheck[0] = startpoint; tcsize = 1; } void mouseClicked() { floodFill(mouseX, mouseY); }