I would like to ignore the corner points (the ones that get green).
This in the selectGridLoc function.
Atm this are the values for i and j;
i j
Quote:-1 -1
-1 0
-1 1
0 -1
0 1
1 -1
1 0
1 1
The combinations that have to be ignored(cause they are for the corners) are the following:
Quote:-1 -1
-1 1
1 -1
1 1
I tried something like:
Code:
// ignore itself
if(i != 0 || j != 0){
//ignore corners
if((i != -1) && (j != -1)){
Only that doesnt work cause a true false gets evaluated as false for examle. During typing this post i found a solution:
if((i == -1 && j == 0) || (i == 0 && j == -1) || (i == 0 && j == 1) || (i == 1 && j == 0)){
Here i don't check for the corners but for the points i want.
But for the purpose of learning, is there a working way to check for the corners?
here's the code:
Code:
void selectGridLoc(int x, int y){
int p = x + (y * w);
g[p] = color(255,0,0);
for(int i = -1; i<=1; i++){
for(int j = -1; j <= 1; j++){
// ignore itself
if(i != 0 || j != 0){
//ignore corners
if((i == -1 && j == 0) || (i == 0 && j == -1) || (i == 0 && j == 1) || (i == 1 && j == 0)){
// neighbour is at np
println(i+" "+j);
int np = (x+i) + (y+j)*w;
g[np] = color(0,255,0);
}
}
}
}
}