// Oscar G. Torres | www.blubee.com // with help from: //* Explode //* by Daniel Shiffman. PImage img; // The source image int cellsize = 2; // Dimensions of each cell in the grid int COLS, ROWS; // Number of columns and rows in our system int ct=0; void setup(){ size(600, 400, P3D); background(0); img = loadImage("karen.jpg"); // Load the image COLS = img.width/cellsize; // Calculate # of columns ROWS = img.height/cellsize; // Calculate # of rows colorMode(RGB,255,255,255,100); // Setting the colormode } void draw(){ // background(0); if (mousePressed == false) { ct=0; } if (mousePressed == true) { ct+=10; 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 monk= cellsize+ct; int x = i*cellsize +cellsize/2; // x position int y = j*cellsize +cellsize/2; // y position int loc = x + y*img.width; // Pixel array location color c = img.pixels[loc]; // Grab the color float rr = round( red(img.pixels[loc]) ); if (rr< 85){ rr=0; } /* if (rr> 85){ rr=127; } */ if (rr > 170){ rr=255; } float gg = round( green(img.pixels[loc])); if (gg< 85){ gg=0; } /* if (rr> 85){ gg=127; } */ if (gg > 170){ gg=255; } float bb = round( blue(img.pixels[loc])); if (bb< 85){ bb=0; } /* if (bb> 85){ bb=127; } */ if (bb > 170){ bb=255; } float tt = rr+gg+bb; // Calculate a z position as a function of mouseX and pixel brightness float z = (ct / (float) img.width) * brightness(img.pixels[loc]) - 100.0f; // (mouseX / (float) img.width) * brightness(img.pixels[loc]) - 100.0f; // Translate to the location, set fill and stroke, and draw the rect pushMatrix(); int xA= x+40; int yA= y+40; float zA= z+40; int cell= cellsize+2; translate(xA,yA,z); fill(rr, gg,bb); noStroke(); rectMode(CENTER); rect(100,50,cellsize,cellsize); //fill(255-rr, 100-gg, 255-bb); //rect(100,50,cellsize/2,cellsize/2); popMatrix(); } } } }