PImage img; // The source image int cellsize = 4; // Dimensions of each cell in the grid int COLS, ROWS; // Number of columns and rows in our system float oldMouseX, oldMouseY, forcedPause, forcedPauseToggle; int modifierToggle = 0; int numImages = 34; float z; int x, y, loc; int minCellsize, maxCellsize; float xRotate, yRotate, zRotate; String cellsizeModifier = "Up"; String imageNumber; float pauseCellsizeModifier = 1; float controlCount; color c; float r, g, b, colorStage, colorStageR, colorStageG, colorStageB; int switchIt = 0; int drawMode, minPause, maxPause; int countPause = 0; float controlCountStep = 0.0002; String countDirection = "Up"; boolean pausable = true; void initializeImages() { for(int i = 1; i < numImages; i ++) { img = loadImage(i +".jpg"); } } void setup() { size(720, 480, P3D); initializeImages(); imageNumber = Integer.toString(int(random(1,numImages + 1))); img = loadImage(imageNumber+".jpg"); // Load the image COLS = width/cellsize; // Calculate # of columns ROWS = height/cellsize; // Calculate # of rows colorMode(RGB,255,255,255,100); // Setting the colormode xRotate = 0; yRotate = 0; zRotate = 0; minCellsize = 4; maxCellsize = 100; } void draw() { background(0); COLS = width/cellsize; // Calculate # of columns ROWS = height/cellsize; // Begin loop for columns if (switchIt == 1) { switchIt = 0; drawMode = int (random(1,11)); x = 1; y = 1; z = 1; xRotate = 0; yRotate = 0; zRotate = 0; println(drawMode); if(random(10) > 5) { controlCountStep = 0.1; minPause = 40; maxPause = 200; pausable = false; } else { controlCountStep = 0.0002; minPause = 60; maxPause = 300; pausable = true; } } //draw2(); if (drawMode == 1) draw1(); else if (drawMode == 2) draw2(); else if (drawMode == 2) draw2(); else if (drawMode == 3) draw3(); else if (drawMode == 4) draw4(); else if (drawMode == 5) draw5(); else if (drawMode == 6) draw6(); else if (drawMode == 7) draw7(); else if (drawMode == 8) draw8(); else if (drawMode == 9) draw9(); else if (drawMode == 10) draw10(); else if (drawMode == 11) draw11(); //getPause(); modifyCellsize(); } void popNDrop() { xRotate = ((PI/3)/width) * controlCount; z -= controlCount/5; y -= (500/width) * controlCount; } void spin() { zRotate = (PI/width) * controlCount; if (controlCount >= 0) { x -= controlCount; y -= controlCount/1.5; } if (controlCount <= 0) { x += controlCount; y += controlCount/1.5; } } void popNSlide() { yRotate = ((PI/2.5)/width) * controlCount; x += controlCount; z += controlCount/2; } void colorWarpInvert() { r = c >> 16 & 0xFF; g = c >> 8 & 0xFF; b = c & 0xFF; //c += color((controlCount), 0, 0, 0);\ colorStageR = (r*2)+((controlCount/(width/2))*(255-(r*2))); colorStageG = (g*2)+((controlCount/(width/2))*(255-(g*2))); colorStageB = (b*2)+((controlCount/(width/2))*(255-(b*2))); r = (colorStageR - red(c)); g = (colorStageG - green(c)); b = (colorStageB - blue(c)); c = color(r, g, b, 100); } void colorWarpBrightness() { z = (controlCount / (float) width) * brightness(img.pixels[loc]) - (80*(controlCount/width)); } void getPause() { if(controlCount == oldMouseX && mouseY == oldMouseY) pauseCellsizeModifier = 0; else { pauseCellsizeModifier = 1; } modifierToggle ++; if(modifierToggle > 15) { oldMouseX = controlCount; oldMouseY = mouseY; modifierToggle = 0; } } void modifyCellsize() { //if(cellsize < 80 && cellsizeModifier == "Up" && pauseCellsizeModifier <= 0) { modifierToggle ++; if(modifierToggle > 15) { pauseCellsizeModifier = 0; modifierToggle = 0; } if(cellsize <= maxCellsize && cellsizeModifier == "Up" && pauseCellsizeModifier == 0 && forcedPause == 0) { cellsize ++; //pauseCellsizeModifier = 5; } else if(cellsize >= minCellsize && cellsizeModifier == "Down" && pauseCellsizeModifier == 0 && forcedPause == 0) { cellsize --; //pauseCellsizeModifier = 5; } if(cellsize == 100) { cellsizeModifier = "Down"; imageNumber = Integer.toString(int(random(1,numImages + 1))); img = loadImage(imageNumber+".jpg"); switchIt = 1; cellsize = 99; } else if(cellsize == minCellsize && forcedPause == 0) { cellsizeModifier = "Up"; forcedPauseToggle = 1; } if(forcedPause > 0) forcedPause -- ; if(forcedPauseToggle == 1) { forcedPauseToggle = 0; cellsize ++; forcedPause = int (random(minPause,maxPause)); } } void controlCountMod() { //controlCount = mouseX; countMethod1(); } void countMethod1() { countPause --; if(controlCount < width && countDirection == "Up" && countPause <= 0){ controlCount += controlCountStep; } if(controlCount >= width) { countDirection = "Down"; } if(controlCount > 0 && countDirection == "Down" && countPause <= 0){ controlCount -= controlCountStep; } if(controlCount <= 0) { countDirection = "Up"; if(pausable == true) { countPause = 50000; controlCount += (3 * controlCountStep); } } } void draw1() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color // Calculate a z position as a function of mouseX and pixel brightness z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw2() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); colorWarpInvert(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw3() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNDrop(); colorWarpInvert(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw4() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNSlide(); colorWarpInvert(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw5() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); spin(); colorWarpInvert(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw6() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNSlide(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw7() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); spin(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw8() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNDrop(); colorWarpInvert(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw9() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNDrop(); colorWarpBrightness(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw10() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); spin(); colorWarpBrightness(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } } void draw11() { for ( int i = 0; i < COLS;i++) { // Begin loop for rows for ( int j = 0; j < ROWS;j++) { controlCountMod(); x = i*cellsize + cellsize/2; // x position y = j*cellsize + cellsize/2; // y position loc = x + y*width; // Pixel array location c = img.pixels[loc]; // Grab the color z = (controlCount / (float) width) * brightness(img.pixels[loc]) - 80.0f; pushMatrix(); popNSlide(); colorWarpBrightness(); rotateX(xRotate); rotateY(yRotate); rotateZ(zRotate); translate(x,y,z); fill(c); noStroke(); rectMode(CENTER); rect(0,0,cellsize,cellsize); popMatrix(); } } }