/***********************create a 2Darray of PixelRects*************************/ int positionsX = 100 ; // deside the width of the array int positionsY = 100; // deside the length of the array PixelRect[][] pixrect = new PixelRect[positionsX][positionsY]; void setup(){ size(400,400); // set the size of the applet window /*************** access all the positions of the array *****************/ int sqSize = round((float)width/ (float)positionsX); for(int i = 0; i < positionsX; i++){ for(int j = 0; j < positionsY; j++){ pixrect[i][j] = new PixelRect( i, j, sqSize, color(random(255))); } } } void draw(){ background(200); /*************** create all the pixelRects of the array *****************/ for (int i = 0; i < positionsX; i++){ for(int j = 0; j < positionsY; j++){ stroke(100); pixrect[i][j].swapColors(); pixrect[i][j].drawPixelRect(); } } } void mousePressed(){ for (int i = 0; i < positionsX; i++){ for(int j = 0; j < positionsY; j++){ pixrect[i][j].setColor(color(random(255))); } } }