//***************************************************************************** // TITLE: Template for 2D geometry // DESCRIPTION: Template to demo points, vectors, frames, bezier curves, animation, tracking, picking, and menus // AUTHOR: Prof Jarek Rossignac // DATE CREATED: January 2008 // EDITS: //***************************************************************************** color red, yellow, green, cyan, blue, magenta, dred, dyellow, dgreen, dcyan, dblue, dmagenta, white, black, orange, grey, metal; // declares color names boolean showHelpText=true, showMenu=true; // toggled by keys to show/hide help text boolean animate=true, showFrame=true, showGhostFrame=false; // changed through menu-toggles to animate and show/hide frame and ghost frame boolean showSubdivision=false, showCurve=true, showConstruction=false; // changed through menu-toggles to animate and show/hide frame and ghost frame boolean printIt=false; // temporarily set when key '?' is pressed and used to print some debugging values pt [] PP = new pt[4]; // decalres an array of 4 points int p=0; // index to the selected point being dragged frame F= new frame (), G= new frame (), T= new frame (), H= new frame (); // declares frames (coordiate systems) int rec=0; // number of recursions in subdividing the Bezier curve float t=0.5, tt=0.5; // parameter defining a point on the curve void reset() {for (int i=0; i=PI*2) tt=0; t=(cos(tt)+1)/2;} else if ((mousePressed)&&(keyPressed)&&mouseIsInWindow()&&(key=='t')) {t+=2.0*(mouseX-pmouseX)/height; fill(black); text("t="+t,20,40); }; // changes value of t and shows it if(showConstruction) {noFill(); stroke(cyan); strokeWeight(3); drawSplitBezier(PP[0],PP[1],PP[2],PP[3],t);}; // draws Bezier curve dfined by them if(showFrame) { // if we want to show the frame that travels on the curve pt P = cubicBezier(PP[0],PP[1],PP[2],PP[3],t); if (printIt) { P.write();} // sets point P on vurve for current t-value vec V = cubicBezierTangent(PP[0],PP[1],PP[2],PP[3],t); V.normalize(); // V is the unit tangent to the curve at P vec N=V.left(); // N is the normal to the curve at P (it points to the right of V because the y-axis goes down) T.setTo(P,V,N); // T is the frame [P V N]. It evolves as the user edits the control polygon or t H.moveTowards(T,0.1); G.moveTowards(H,0.1); F.moveTowards(G,0.1); // ghost frames chain each chasing the previous: F->G->H->T if(showGhostFrame) {fill(yellow); stroke(yellow); F.show(); pushMatrix(); F.apply(); ellipse(0,0,40,20); popMatrix();}; // show F as vectors and ellipse fill(orange); stroke(dgreen); T.show(); pushMatrix(); T.apply(); ellipse(0,0,40,20); popMatrix(); // show T as vectors and ellipse } }; if(showMenu) {strokeWeight(1); Buttons.show(); Toggles.show(); text("Demo of GEOMETRY ",width-290,280); text("built in Processing by Jarek Rossignac",width-290,300); } printIt=false; }; // end of draw