import processing.pdf.*; //constants int NONE = 0; int BASE1 = 1; int BASE2 = 2; int P1 = 3; int P2 = 4; int P3 = 5; int P4 = 6; int B1_P = 7; int B2_P = 8; int B3_P = 9; int B4_P = 10; int T1_P = 11; int T2_P = 12; int T3_P = 13; int T4_P = 14; int B1_E = 15; int B2_E = 16; int B3_E = 17; int B4_E = 18; int T1_E = 19; int T2_E = 20; int T3_E = 21; int T4_E = 22; int PDF_B = 23; int UMBRA=4; int PENUMBRA=5; // write pdf? boolean applet = true; boolean record = false; //control points int control=NONE; Point plan_bline_1, plan_bline_2; // perspective points BLinePoint p1, p2, p3, p4; //corner points Point b1, b2, b3, b4; Point t1, t2, t3, t4; Point last; Point centroid; Point button_pdf; // unfold points Point t1a, t2a, t3a, t4a, t1b, t2b, t3b, t4b; Point t4c, t1c, t2c, t3c; // lid // perspective lines RLine plan_p1b2, plan_p1t2, plan_p2b3, plan_p2t3, plan_p3b1, plan_p3t1, plan_p4b2, plan_p4t2; RLine el_p1t2, el_p2t3, el_p3t1, el_p4t2; HLine fold; HLine el_bline; BLine plan_bline; //unfold lines Line b1t1a, b1t1b, b2t2a, b2t2b, b3t3a, b3t3b, b4t4a, b4t4b; // legs Line t1b_t2a, t2b_t3a, t3b_t4a, t4b_t1a; // bridges Line t2b_t1c, t1c_t4c, t4c_t3a; // lid //formatting PFont font; void setup() { size(700,600); noFill(); background(0); font=loadFont("Monospace821BT-Roman-12.vlw"); textFont(font); // set initial vals plan_bline_1 = new Point(0,(height/2) + 75); plan_bline_2 = new Point(width,height/2); plan_bline = new BLine(plan_bline_1, plan_bline_2); plan_bline.setColor(100); el_bline = new HLine(height-25); el_bline.setColor(100); fold = new HLine(height/2 + 100); fold.setColor(0,0,155); p1 = new BLinePoint(50, el_bline, plan_bline, "V1"); p2 = new BLinePoint(100, el_bline, plan_bline, "V2"); p3 = new BLinePoint(500, el_bline, plan_bline, "V3"); p4 = new BLinePoint(575, el_bline, plan_bline, "V4"); p1.setColor(255,0,0); p2.setColor(255,0,0); p3.setColor(255,0,0); p4.setColor(255,0,0); Point[] p_arr = {p1,p2,p3,p4}; plan_bline_1.children = p_arr; plan_bline_2.children = p_arr; initCornerPoints(); //perspective lines plan_p1b2 = new RLine(p1, b2); plan_p1t2 = new RLine(p1, t2); plan_p2b3 = new RLine(p2, b3); plan_p2t3 = new RLine(p2, t3); plan_p3b1 = new RLine(p3, b1); plan_p3t1 = new RLine(p3, t1); plan_p4b2 = new RLine(p4, b2); plan_p4t2 = new RLine(p4, t2); el_p1t2 = new RLine(p1, t2, ELEVATION); el_p2t3 = new RLine(p2, t3, ELEVATION); el_p3t1 = new RLine(p3, t1, ELEVATION); el_p4t2 = new RLine(p4, t2, ELEVATION); b1.onLines(plan_p1b2, plan_p3b1); t1.onLines(plan_p1t2, plan_p3t1); t1.onLinesZ(el_p1t2, el_p3t1); b2.onLines(plan_p1b2, plan_p4b2); t2.onLines(plan_p1t2, plan_p4t2); t2.onLinesZ(el_p1t2, el_p4t2); b3.onLines(plan_p4b2, plan_p2b3); t3.onLines(plan_p4t2, plan_p2t3); t3.onLinesZ(el_p4t2, el_p2t3); b4.onLines(plan_p2b3, plan_p3b1); t4.onLines(plan_p2t3, plan_p3t1); t4.onLinesZ(el_p2t3, el_p3t1); p4.initChildren(t3, b3); p3.initChildren(b4, t4); p2.initChildren(b4, t4); p1.initChildren(b1, t1); t1.initChildren(t4); b1.initChildren(b4); t3.initChildren(t4); b3.initChildren(b4); b2.initChildren(b1, b3); t2.initChildren(t1, t3); b4.children = new Point[0]; t4.children = new Point[0]; last = t1; // set the default button_pdf = new Point(width-10, 10); } void draw() { if (mousePressed) { if (control == PDF_B) { record = true; } // make PDF if (control == P1) { last=p1;last.focus=PLAN;p1.X(mouseLimits(0,width,mouseX)); } if (control == P2) { last=p2;last.focus=PLAN; p2.X(mouseLimits(0,width,mouseX)); } if (control == P3) { last=p3;last.focus=PLAN; p3.X(mouseLimits(0,width,mouseX)); } if (control == P4) { last=p4;last.focus=PLAN; p4.X(mouseLimits(0,width,mouseX)); } if (control == B1_P) { last=b1; last.focus=PLAN; b1.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == B2_P) { last=b2; last.focus=PLAN; b2.X(mouseLimits(0,width,mouseX)); b2.Y(mouseLimits(0,fold.height,mouseY)); } if (control == B3_P) { last=b3; last.focus=PLAN; b3.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == B4_P) { last=b4; last.focus=PLAN; b4.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == T1_P) { last=t1; last.focus=PLAN; t1.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); } if (control == T2_P) { last=t2; last.focus=PLAN; t2.X(mouseLimits(0,width,mouseX)); t2.Y(mouseLimits(0,fold.height,mouseY)); } if (control == T3_P) { last=t3; last.focus=PLAN; t3.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); t2.X(t2.x); } if (control == T4_P) { last=t4; last.focus=PLAN; t4.reposition(mouseLimits(0,width,mouseX), mouseLimits(0,fold.height,mouseY)); t2.X(t2.x); } if (control == B1_E) { last=b1; last.focus=ELEVATION; b1.slideX(mouseLimits(0,width,mouseX)); } if (control == B2_E) { last=b2;last.focus=ELEVATION; b2.slideX(mouseLimits(0,width,mouseX)); } if (control == B3_E) { last=b3;last.focus=ELEVATION; b3.slideX(mouseLimits(0,width,mouseX)); } if (control == B4_E) { last=b4;last.focus=ELEVATION; b4.slideX(mouseLimits(0,width,mouseX)); } if (control == T1_E) { last=t1;last.focus=ELEVATION; t1.repositionZ(mouseLimits(0,width,mouseX),mouseLimits(fold.height, el_bline.height, mouseY)); } if (control == T2_E) { last=t2;last.focus=ELEVATION; t2.X(mouseLimits(0,width,mouseX)); t2.Z(mouseLimits(fold.height, el_bline.height, mouseY)); } if (control == T3_E) { last=t3;last.focus=ELEVATION; t3.repositionZ(mouseLimits(0,width,mouseX), mouseLimits(fold.height, el_bline.height, mouseY)); } if (control == T4_E) { last=t4;last.focus=ELEVATION; t4.repositionZ(mouseLimits(0,width,mouseX), mouseLimits(fold.height, el_bline.height, mouseY)); t2.X(t2.x); } if (control == BASE1) { plan_bline.start.Y(mouseLimits(0, fold.height, mouseY)); } if (control == BASE2) { plan_bline.end.Y(mouseLimits(0, fold.height, mouseY)); } } // find the centroid Line temp1 = new Line(b1, b3); Line temp2 = new Line(b2, b4); float xx = temp1.getIntersect(temp2); centroid = new Point(xx, temp1.getY(xx)); // unfold the sucker away from the centroid t2b = plan_p4b2.unfoldPt(t2, b2); t3a = plan_p4b2.unfoldPt(t3, b3); t3b = plan_p2b3.unfoldPt(t3, b3); t4a = plan_p2b3.unfoldPt(t4, b4); t4b = plan_p3b1.unfoldPt(t4, b4); t1a = plan_p3b1.unfoldPt(t1, b1); t1b = plan_p1b2.unfoldPt(t1, b1); t2a = plan_p1b2.unfoldPt(t2, b2); t1c = plan_bline.unfoldPt(t1, p3); t2c = plan_bline.unfoldPt(t2, p4); t3c = plan_bline.unfoldPt(t3, p4); t4c = plan_bline.unfoldPt(t4, p3); // mirror the geometry of the lid to unfold intuitively Line m = new Line(t3c, t2c); m.mirror(t1c); m.mirror(t4c); // translate the whole thing over float dx = t3a.x - t3c.x; float dy = t3a.y - t3c.y; t1c.x += dx; t1c.y += dy; t2c.x += dx; t2c.y += dy; t3c.x += dx; t3c.y += dy; t4c.x += dx; t4c.y += dy; // now rotate into place about t3c // start with the known rotation -- t2c to t2b float c = dist(t3c.x, t3c.y, t2c.x, t2c.y); float b = t2c.y - t3c.y; float a = t2c.x - t3c.x; float a_pri = t2b.x - t3c.x; float b_pri = t2b.y - t3c.y; float alph = atan(b / a); float beta = atan(b_pri / a_pri); float theta = (cos(beta)*cos(alph) < 0) ? beta-alph : PI+beta-alph; t2c.rotateAbout(t3c, theta); t4c.rotateAbout(t3c, theta); t1c.rotateAbout(t3c, theta); drawEm(); } void mousePressed() { control = chooseControl(); } int chooseControl() { if (abs(mouseX - p1.x) < UMBRA && (abs(mouseY - el_bline.height) < UMBRA || abs(mouseY - p1.y) lower) { return lower; } else if (val < upper) { return upper; } else return val; } // get the y coordinate at point x on a line spanning width of screen // simpler version of setPt() float getY(float x, float y1, float y2) { float a = (y2-y1)/width; return (a*x)+y1; } // find y coordinate at point x on line given by endpoints float setPt(float x, float x1, float y1, float x2, float y2) { float a = (y2-y1)/(x2-x1); float b = y1-(a*x1); return (a*x)+b; } // returns x coordinate of intersection of two lines float intersect(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4) { float a1 = (y2-y1)/(x2-x1); float a2 = (y4-y3)/(x4-x3); float b1 = y1 - (a1*x1); float b2 = y3 - (a2*x3); return (b2 - b1)/(a1 - a2); }