// Mouse horizontal location controls breaking apart of image and // Maps pixels from a 2D image into 3D space. Pixel brightness controls // translation along z axis. PImage img; // This is the source image int cellsize = 2; // This is the dimentions of the cells in each grid int COLS, ROWS; // This means the number of columns and rows in grid void setup() { size(400, 400, P3D); // Make sure the image pixel is the same as size pixel img = loadImage("earth.jpg"); // This is a way to load image from COLS = width/cellsize; // Calculates the # of columns ROWS = height/cellsize; // Calculates the # of rows colorMode(RGB,255,255,255,100); // This sets the colormode } void draw() { background(0); // Begin loop for columns for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { int x = i*cellsize + cellsize/2; // x position int y = j*cellsize + cellsize/2; // y position int loc = x + y*width; // This is the pixel array location color c = img.pixels[loc]; // Grabs the color // Calculates a z position as a function of mouseX and pixel brightness float z = (mouseX / (float) width) * brightness(img.pixels[loc]) - 100.0f; // Translate to the location, sets fill and stroke, and draw the rect pushMatrix(); // Pushes the current transformation matrix onto the matrix stack translate(x,y,z); // Specifies an amount to displace objects within the display window fill(c); // Sets the color used to fill shapes noStroke(); // Disables drawing the stroke (outline). If both noStroke() and noFill() are called, nothing will be drawn to the screen. rectMode(CENTER);// Modifies the location from which rectangles draw (in this case, it is the CINTER) rect(0,0,cellsize,cellsize); // Draws a rectangle to the screen. A rectangle is a four-sided shape with every angle at ninety degrees. The first two parameters set the location, the third sets the width, and the fourth sets the height. The origin is changed with the rectMode() function. popMatrix(); // Pops the current transformation matrix off the matrix stack } } }