// JESSICA PORRETTA // PROBLEM SET 4 // REMIX OF PUSHPOPCUBES /** * Color controlled by mouse over animation */ // Spiral Staircase // Changes color when mouse goes over animation // Cube class required float ang; int rows = 20; int cols = 10; int cubeCount = rows*cols; int colSpan, rowSpan; float rotspd = 2.0; Cube[] cubes = new Cube[cubeCount]; float[] angs = new float[cubeCount]; float[] rotvals = new float[cubeCount]; void setup(){ size(744, 744, P3D); colSpan = width/(cols-3); rowSpan = height/(rows-1); noStroke(); // instantiate cubes for (int i = 0; i < cubeCount; i++){ cubes[i] = new Cube(43, 12, 46, 30, 100, 100); rotvals[i] = rotspd += 0.01; } } void draw(){ int cubeCounter = 0; background(0); fill(255, 255, 255); // Different colored lights // As the mouse moves over the image, the color changes pointLight(150, mouseX, 200, width/4, height/3, 120); pointLight(50, mouseY, 200, width/4, height/3, -150); // Light in animation ambientLight(0, 30, 23); // Translate, rotate and draw cubes for (int i = 0; i < cols; i++){ for (int j = 0; j < rows; j++){ pushMatrix(); translate(i * colSpan, j * rowSpan, -30); //rotate each cube around y and x axes rotateY(radians(angs[cubeCounter])); rotateX(radians(angs[cubeCounter])); cubes[cubeCounter].drawCube(); popMatrix(); cubeCounter++; } } // Angs used in rotate function calls above for (int i = 0; i < cubeCount; i++){ angs[i] += rotvals[i]; } } // Simple Cube class, based on Quads class Cube { // Properties int w, h, d; int shiftX, shiftY, shiftZ; // Constructor Cube(int w, int h, int d, int shiftX, int shiftY, int shiftZ){ this.w = w; this.h = 50; this.d = 40; this.shiftX = shiftX; this.shiftY = shiftY; this.shiftZ = shiftZ; } void drawCube(){ // Front face beginShape(QUADS); vertex(-w*2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); vertex(-w*2 + shiftX, h + shiftY, -d/2 + shiftZ); // Back face vertex(-w*2 + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); vertex(-w*2 + shiftX, h + shiftY, d + shiftZ); // Left face vertex(-w*2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(-w*2 + shiftX, -h/2 + shiftY, d + shiftZ); vertex(-w*2 + shiftX, h + shiftY, d + shiftZ); vertex(-w*2 + shiftX, h + shiftY, -d/2 + shiftZ); // Right face vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); vertex(w + shiftX, h + shiftY, -d/2 + shiftZ); // Top face vertex(-w*2 + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, -d/2 + shiftZ); vertex(w + shiftX, -h/2 + shiftY, d + shiftZ); vertex(-w*2 + shiftX, -h/2 + shiftY, d + shiftZ); // Bottom face vertex(-w*2 + shiftX, h + shiftY, -d*2 + shiftZ); vertex(w + shiftX, h + shiftY, -d*2 + shiftZ); vertex(w + shiftX, h + shiftY, d + shiftZ); vertex(-w*2 + shiftX, h + shiftY, d + shiftZ); endShape(); } }