I am trying to figure out the formula for the loc position on line 31 but i can't figure it out. Can anyone guide me to a solution?
PImage theImage;
int cellSize = 6; // dimension of a cell where logic is applied
int cols, rows; // number of rows and columns based on cellsize
int col; // column in the cell
int row; // row in the cell
float edgeR; // (amount of red in the corners)
float edgeB; // (amount of blue in the corners)
float edgeG; // (amount of green in the corners)
float middleR; // (amount of red in the center)
float middleB; // (amount of blue in the center)
float middleG; // (amount of green in the center)
void setup()
{
size(1570,1112); // fits the image
theImage = loadImage("im.png"); // load the image
cols = width/cellSize ; // number of colums in the grid of the image
rows = height/cellSize ; // number of rows in the grid of the image
}
void draw ()
{
background(0);
loadPixels();
theImage.loadPixels(); // load every pixel of the image in an array
image(theImage,0,0); // display the image at pos 0 0
for ( int i=0; i< rows;i++) {
for ( int j = 0; j< cols;j++) { // loop matrix of cells
for ( int x = i*cellSize; x<i*cellSize+cellSize;x++) {
for ( int y = j*cellSize; y<j*cellSize+cellSize;y++) { //
loop every pixel of the cell
---> int loc = (i*cellSize+x) +
(j*cellSize*width+y*cellSize*width); // grrrrr <-----
float r = red(theImage.pixels[loc]); // red value
float g = green(theImage.pixels[loc]); // green value
float b = blue(theImage.pixels[loc]); // blue value
if (x - i*cellSize <= cellSize /3 ) { // it is in a column 1
col = 1;
}
else if (x - i*cellSize >= cellSize*2/3 ) { // it is in a column 3
col = 3;
}
else {
col = 2; // it is in a column 2
}
if (y - j*cellSize <= cellSize /3 ) { // it is in row 1
row = 1;
}
else if (y - j*cellSize >= cellSize*2/3) { // it is in row 3
row = 3;
}
else { // in row 2
row = 2;
}
if (col == 1 & row ==1 || (col == 3 & row == 3) || (col == 1 & row == 3) || (col == 3 & row == 1)) {
edgeR = edgeR + r; // aggregate the edge color values
edgeG = edgeG + g;
edgeB = edgeB + b;
}
else {
middleR = middleR + r; // aggregate the center color values
middleG = middleG + g;
middleB = middleB + b;
// here some magic will be applied if there would be no ArrayIndexOutOfBoundsException: 1745840 error
}
}
}
}
}
}
When I run the code the output window freezes and I get an ArrayIndexOutOfBoundsException: 1752120 error/ if i put debugging on this also keep saying: debugger busy.
I am pretty sure the loc position is incorrect, but i don't have an idea how to fix the formula. Also the nested for loop might be the issue as well.
Thanks a lot for any help, it is very much appreciated.
All the best,
Tim