hello again,
first off, thanks for helping me crunch this out, your suggestions and help is greatly appreciated.
Boolean array for each pixel was the approach I needed.
Your assumption that I eventually want more than 2 rects was correct. I therefore have attempted to make a class for this but I ran into some early problems. Here is my first attempt at it with help from your sample code:
Code:
//frames
//mad props to pedro veneroso to help me figuring this one out
boolean[] r1b, r2b;
int numPixels;
Frame[] framey;
void setup () {
background(255);
size(500, 500);
numPixels = width * height;
framey = new Frame[2];
for(int i = 0; i < 2; i++) {
framey[i] = new Frame(150, 100, 200, 200);
}
}
void draw () {
framey[0].display();
}
class Frame
{
int rx,ry,rxsize,rysize;
boolean[] r1b, r2b;
int[] r1,r2;
color thisC;
Frame(int xx, int yy, int xsize, int ysize) {
rx = xx;
ry = yy;
rxsize = xsize;
rysize = ysize;
//couldnt get these varibles to pass to int[] r1 here moved to display method
//kept getting null pointer exception
r1b = new boolean[numPixels];
r2b = new boolean[numPixels];
thisC = color(0);
}
void display () {
pushStyle();
fill(128);
noStroke();
int[] r1 = {rx,ry,rxsize,rysize};
int[] r2 = {100,200,200,200};
rect(r1[0], r1[1],r1[2], r1[3]);
rect(r2[0], r2[1], r2[2], r2[3]);
popStyle();
loadPixels();
for(int i = 0; i < numPixels; i ++)
{
if((i/width) > r1[1] && (i/width) < (r1[1] + r1[3])
&& (i%width) > r1[0] && (i%width) < (r1[0] + r1[2]))
{
r1b[i] = true;
}
else{r1b[i] = false;}
}
for(int x = 0; x < numPixels; x ++)
{
if((x/width) > r2[1] && (x/width) < (r2[1] + r2[3])
&& (x%width) > r2[0] && (x%width) < (r2[0] + r2[2]))
{
r2b[x] = true;
}
else{r2b[x] = false;}
}
for(int y = 0; y < numPixels; y++)
{
if(r1b[y] == true && r2b[y] == true)
{
pixels[y] = thisC;
}
}
updatePixels();
}
}
like i mention in my code, i couldnt get the varibles (rx,ry,etc) to pass to the r1,r2 array in my arguments, which is where i thought that should go, but i guess not.
I only made 2 rects (like you had in the sample) because I wasnt sure how making multiple rects or an array of them would work with the meat of your code (for and if statements) which I am still trying to wrap my head around.
Eventually, I think I want my class just to make one rect, and then check the others already made for intersections, and fill them and so forth.
thanks again for your help!