I'm working on a paint program, and I have a canvas (a blank white PImage) that I want to refresh to white and println() some text when the user clicks a button, but only when there is something drawn on the canvas.
I have some code that scans through the canvas's pixel array. It has a boolean, blankCanvas, that controls the println() and canvas refresh functions.
loadPixels();
for (int i = 0; i < canvas.pixels.length; i ++) {
if (canvas.pixels[i] == color(255)) {
blankCanvas = true;
}
}
for (int i = 0; i < canvas.pixels.length; i ++) {
if (canvas.pixels[i] == color(255)) {
blankCanvas = true;
}
}
This code seems to return blankCanvas as true as long as
any one pixel is white. So, if the user draws something in another color but doesn't fill the whole canvas with it, blankCanvas returns as true. The only time blankCanvas doesn't come back as true is when the entire canvas is filled with a color other than white. I only want it to return as true if
all the pixels are white (i.e., I want blankCanvas to be true only when the canvas is actually blank).
So, I think I'm just having trouble figuring out how to access an array in this way. I think my question is: is there a way to scan through a pixel array and return a true value only if
all the pixels in the array are white? Or, in other words: is there a way to check whether any one or more pixels in a pixel array are
not white and then return a false value? Thank you in advance!
1