PImage pic; int picDimension; color temporaryColor; int positionsX = 150; int positionsY = 150; /***********************create a 2Darray of PixelRects*************************/ PixelRect[][] pixrect; float rotX; float rotY; float rotZ; void setup(){ frameRate(30); pic = loadImage("japanFoto.jpg"); // load a picture, you have added to the file size(pic.width, pic.height, P3D); println("w " +pic.width + " h " +pic.height); image(pic,0,0); // place the image at the upper left corner of the applet picDimension = (pic.width*pic.height); // to get how many pixels the picture has println("Number of Pixels of the pic: " + picDimension); pixrect = new PixelRect[pic.width][pic.height]; int sqSize = (int)((pic.width/positionsX)/2); // dimensions of each pixelrect in the grid /*************** access all the positions of the array *****************/ for(int i = 0; i < pic.width; i++){ for(int j = 0; j < pic.height; j++){ temporaryColor = pic.pixels[j*pic.width+i]; // to get the color of each pixel of the picture pixrect[i][j] = new PixelRect(i, j, sqSize, temporaryColor); } } } void draw(){ background(200); rotateX(rotX); rotateY(rotY); rotateZ(rotZ); for (int i = 0; i < pic.width; i++){ for(int j = 0; j < pic.height; j++){ noStroke(); pixrect[i][j].swapColors(); pixrect[i][j].drawPixelRect(); } } } void mouseDragged() { if(mouseButton == LEFT) { rotY += ((mouseX - pmouseX) * 0.01); rotX -= ((mouseY - pmouseY) * 0.01); }else if(mouseButton == RIGHT) { rotZ += ((mouseX - pmouseX) * 0.01); } }