// voxels? --> ok, not really voxels, but cubes in a grid // mikkel . crone . koser // http://www.beyondthree.com // proce55ing.beyondthree.com Voxel[] allVoxels; BImage bg; String dir = "down"; //int POP = 100; int dim = 40; int xPOP = 6; int yPOP = 6; void setup(){ size(360, 360); bg = loadImage("bg.gif"); // populate allVoxels allVoxels = new Voxel[xPOP * yPOP]; for(int j = 0; j < yPOP; j++){ for(int i = 0; i < xPOP; i++){ allVoxels[(j*yPOP) + i] = new Voxel(i*(width/xPOP) + (width/xPOP)/2, j*(height/yPOP) + (width/yPOP)/2); } } } void keyPressed(){ if(key == UP){ dir = "up"; }else if(key == DOWN){ dir = "down"; }else if(key == LEFT){ dir = "left"; }else if(key == RIGHT){ dir = "right"; }else if(key == '1'){ dim = 25; }else if(key == '2'){ dim = 30; }else if(key == '3'){ dim = 35; }else if(key == '4'){ dim = 40; }else if(key == '5'){ dim = 45; }else if(key == '6'){ dim = 50; }else if(key == '7'){ dim = 55; }else if(key == '8'){ dim = 60; } } void loop(){ background(bg); translate(0, 0, -50); //background(255); // render voxels for(int j = 0; j < yPOP; j++){ for(int i = 0; i < xPOP; i++){ //allVoxels[(j*yPOP) + i] = new Voxel(i*xPOP, j*yPOP); allVoxels[(j*yPOP) + i].render(); } } } class Voxel{ int x, y; int xDist, yDist; float rotX, rotY; Voxel(int xx, int yy){ x = xx; y = yy; } void render(){ // relationship with mouse xDist = abs(mouseX - x); yDist = abs(mouseY - y); // draw it push(); // focus translate(x, y); // mouseWITHIN if(xDist <= dim/2 && yDist <= dim/2){ stroke(255, 200, 0); if(dir == "down"){ rotX = PI/2; }else if(dir == "up"){ rotX = 0; }else if(dir == "left"){ rotY = PI/2; }else if(dir == "right"){ rotY = 0; } }else{ stroke(0, 0, 0); if(dir == "down"){ rotX = rotX - 0.1; rotX = max(0, rotX); }else if(dir == "up"){ rotX = rotX + 0.1; rotX = min(PI/2, rotX); }else if(dir == "left"){ rotY = rotY - 0.1; rotY = max(0, rotY); }else if(dir == "right"){ rotY = rotY + 0.1; rotY = min(PI/2, rotY); } } // rotate if(rotX != 0){ if(dir == "left" || dir == "right"){ rotX = rotX - 0.1; rotX = max(0, rotX); } } rotateX(rotX); if(rotY != 0){ if(dir == "up" || dir == "down"){ rotY = rotY - 0.1; rotY = max(0, rotY); } } rotateY(rotY); // draw box(dim); pop(); } }