// Jarl Midelfort - Connect the Boxes int numero = 1; int numero2; //instance of the class that will be used for the reference box (the shape you are going to make) makeOne makeHer = new makeOne(); //arrays that will have x, y, & z positions put into them as more boxes are added to the chain float[] NumZ = new float[1000]; float[] NumY = new float[1000]; float[] NumX = new float[1000]; // variables that will play roles in the making and trasforming/positioning of the boxes float test1 = -100; float test2; float test3; float one = -150; float one2; float yVar = 150; float yVar2; int zAxis; boolean runOK; //flag for whether to run boolean restart; // variables that will make movement occur float theta=0; float theta2=0; void setup() { background(255); size(500, 500, P3D); PFont fontA = loadFont("LiGothicMed-48.vlw"); textFont(fontA,48); fill(0); text("Directions:", (width/20), (height/10)); textFont(fontA,24); fill(90,90,90); text("Press the Down or Up keys to move in and out of space", (width/15), ((height/10)*2)); text("Press the Control key to start over.", (width/15), (height/10)*3); textFont(fontA,24); text("Click here to start!", (width/15), (height/10)*4); restart = true; } void draw() { if (runOK) { if (restart) { background(255); lights(); // here is the camera mover(); // incrementing these variables for movement theta += 0.01; theta2 += 0.01; // movement will be created with these rotations occuring each time the draw cycle loops rotateX(theta2/numero); rotateY(theta2/numero); rotateZ(theta/numero); // And here comes the for loop- every time the mouse is upped, numero will increment by one, adding a new box into the // draw cycle. NumX, Y and Z are positions that we are translating each of the boxes by in order to create a chain // effect. The NumX, Y & Z array's store new positions for each new box that is created. We reference these positions // in the for loop using the i value as the array position and the box number we are creating, and we build a chain // by compounding translations of each box. By setting test3, yVar2 and one2 as the current corresponding array position, // we are telling our boxes were they should plot their points in relation to the previous positions. makeHer.rectanglo(); is // calling the function for the reference box after the others have been made so that the translation effects it and we // see the reference box where it is going to end up. for (int i = 1; i <= numero; i++) { // here is the function that will make the reference box extrude according to mouseX/mouseY when mouse down extrude(); translate(NumX[i-1], NumY[i-1], NumZ[i-1]); test3 = NumZ[i]; yVar2 = NumY[i]; one2 = NumX[i]; makeHer.rectNew(); } makeHer.rectanglo(); } } if (!restart) { for (int j = 0; j <= numero; j++) { NumZ[j] = 0; NumY[j] = 0; NumX[j] = 0; } test2 = 0; yVar = 0; one = 0; numero = 1; zAxis = 0; theta = 0; theta2 = 0; } } void extrude() { if (mousePressed) { test2 = 12*(mouseY-400); yVar2 = (mouseX-200); one2 = (mouseX-200); } float difX = one-one2; float difY = yVar-yVar2; float difZ = test1-test2; //causes settings to "coast" naturally for (int i = 0; i <= numero; i++) { if((i >= numero) && (i <= numero)) { if (abs(difZ) > NumZ[i]) { test1 -= difZ/20.0; } if (abs(difY) > NumY[i]) { yVar -= difY/20.0; } if (abs(difX) > NumX[i]) { one -= difX/20.0; } } } } void mover() { for (int i = 1; i <= numero; i++) { camera(0.0, 0.0, 10000+abs(NumZ[i])+zAxis, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } } void keyPressed () { if (key == CODED) { if (keyCode == UP) { zAxis += 50*numero; } } if (key == CODED) { if (keyCode == DOWN) { zAxis -= 50*numero; } } if (key == CODED) { if (keyCode == CONTROL) { restart = !restart; } } } void mouseReleased() { //erase the text drawn when starting background(255); //do you like this statement here? //only do this once (dont let another mouseclick reset this) if (!runOK) { runOK = true ; } println("Mouse released, and runOK="+runOK); numero += 1; NumZ[numero-1] = test2; NumY[numero-1] = yVar; NumX[numero-1] = one; println("array number: "+numero+" test2: "+test2); } class makeOne { // Constructor /* makeOne(int one_) { int one = one_; }*/ void rectNew() { rotateX(theta); rotateY(theta); noStroke(); // backSide fill(10, 10, 10); beginShape(); vertex(one2-one2*2, yVar2, -200); vertex(one2, yVar2, -200); vertex(one2, -yVar2, -200); vertex(one2-one2*2, -yVar2, -200); endShape(); // frontSide fill(100, 100, 50); beginShape(); vertex(one2-one2*2, yVar2, test3); vertex(one2, yVar2, test3); vertex(one2, -yVar2, test3); vertex(one2-one2*2, -yVar2, test3); endShape(); // Top Short Side fill(100, 150, 50); beginShape(); vertex(one2-one2*2, yVar2, -200); vertex(one2-one2*2, yVar2, test3); vertex(one2, yVar2, test3); vertex(one2, yVar2, -200); endShape(); // bottom short side beginShape(); vertex(one2-one2*2, -yVar2, -200); vertex(one2-one2*2, -yVar2, test3); vertex(one2, -yVar2, test3); vertex(one2, -yVar2, -200); endShape(); // Long side Left beginShape(); vertex(one2-one2*2, yVar2, -200); vertex(one2-one2*2, -yVar2, -200); vertex(one2-one2*2, -yVar2, test3); vertex(one2-one2*2, yVar2, test3); endShape(); // Long side Right beginShape(); vertex(one2, yVar2, -200); vertex(one2, -yVar2, -200); vertex(one2, -yVar2, test3); vertex(one2, yVar2, test3); endShape(); } void rectanglo() { rotateX(cos(theta)); rotateY(sin(theta)); noStroke(); // backSide fill(10, 10, 10); beginShape(); vertex(one-one*2, yVar, -200); vertex(one, yVar, -200); vertex(one, -yVar, -200); vertex(one-one*2, -yVar, -200); endShape(); // frontSide fill(100, 100, 50); beginShape(); vertex(one-one*2, yVar, test1); vertex(one, yVar, test1); vertex(one, -yVar, test1); vertex(one-one*2, -yVar, test1); endShape(); // Top Short Side fill(100, 150, 50); beginShape(); vertex(one-one*2, yVar, -200); vertex(one-one*2, yVar, test1); vertex(one, yVar, test1); vertex(one, yVar, -200); endShape(); // bottom short side beginShape(); vertex(one-one*2, -yVar, -200); vertex(one-one*2, -yVar, test1); vertex(one, -yVar, test1); vertex(one, -yVar, -200); endShape(); // Long side Left beginShape(); vertex(one-one*2, yVar, -200); vertex(one-one*2, -yVar, -200); vertex(one-one*2, -yVar, test1); vertex(one-one*2, yVar, test1); endShape(); // Long side Right beginShape(); vertex(one, yVar, -200); vertex(one, -yVar, -200); vertex(one, -yVar, test1); vertex(one, yVar, test1); endShape(); } }