PImage img; void setup() { img = loadImage("spiralthing.png"); image(img, 0, 0); size(1000, 1000); } void draw() { } int tocheck[] = new int[100000]; int tcsize = 0; void floodFill(int x, int y) { loadPixels(); int startpoint = x + y*width; tocheck[0] = startpoint; tcsize = 1; while (tcsize > 0) { // 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(pixels[curr]) < 128) { pixels[curr] = color(255, 0, 0); if(curr - width > 0 && red(pixels[curr - width]) < 128 ){ tocheck[tcsize] = curr - width; tcsize++; } if(curr + width < (height * width) && red(pixels[curr + width]) < 128 ){ tocheck[tcsize] = curr + width; tcsize++; } if(curr - 1 > 0 && red(pixels[curr - 1]) < 128 ){ tocheck[tcsize] = curr - 1; tcsize++; } if(curr + 1 < width*height && red(pixels[curr + 1]) < 128 ){ tocheck[tcsize] = curr + 1; tcsize++; } } } updatePixels(); } void mouseClicked() { floodFill(mouseX, mouseY); }