//***************************************************************************** // TITLE: Refine // DESCRIPTION: To show refine process in a polyloop // AUTHOR: Sungbae Kim // DATE CREATED: Sep. 3. 2007 // EDITS: //***************************************************************************** boolean showText = true; // toggled by key to show/hide help text boolean printIt=false; // temporarily set when a key is pressed and used to print some debugging values int mousepoint; //! n is the total number of points. int n=4; //! decalres an array of n points pt [] PP = new pt[n]; int p=0; // index to the point being dragged // Those are predefined colors of Professor Jarek. color red, yellow, green, cyan, blue, magenta, dred, dyellow, dgreen, dcyan, dblue, dmagenta, white, black, orange, grey, metal; // declares colors Vector polyloop = new Vector(); boolean refine = false; boolean reset = false; int refinetimes = 0; class vertex { pt P; boolean isNew; vertex() { P = new pt(); isNew = false; } } void resetPolyloop() { polyloop.clear(); for (int i=0; i i*2 + 1 ) polyloop.add( i*2+1, newV ); else polyloop.add(newV); } refine = false; refinetimes++; } else if ( reset == true ) { resetPolyloop(); reset = false; refinetimes = 0; } background(121); // sets background strokeWeight(1); // sets weight of stroke if (showText) {fill(dblue); pushMatrix(); translate(20,20); fill(dblue); text("* Press 'r' to refine : now - " + refinetimes + " times",0,0); translate(0,20); text("* Press 'e' to reset",0,0); translate(0,20); popMatrix(); noFill();}; strokeWeight(2); stroke(green); noFill(); beginShape(); for ( int i = 0; i < polyloop.size(); i++ ) { vertex v = (vertex) polyloop.elementAt(i); v.P.v(); } endShape(CLOSE); noStroke(); for ( int i = 0; i < polyloop.size(); i++ ) { vertex v = (vertex) polyloop.elementAt(i); if ( v.isNew ) fill(red); else fill(green); v.P.show(2); } }; /** @brief This function is called when the user press any key in keyboard.\n \n When user press any key in keyboard, this function will check which key has been pressed.\n We modified Professor Jarek's code in this function.\n We added a logic to check key '0', '1' and '3' to show different results and we also added a logic 'm' to display different mode of program. @param none. @return none. */ void keyPressed() { if (key=='h') showText = !showText; if (key=='?') printIt = true; // sets the debugging mode for one pass if ( key == 'r') { refine = true; } else if ( key == 'e' ) { reset = true; } } /** @brief This function is called when the mouse is being clicked.\n \n When user clicks mouse button on certain point, this function will make users to be able to drag it.\n The actual idea of doing this is kind of make the point stick to current position of the cursor.\n I used Professor Jarek's code in this function. @param none. @return none. */ void mousePressed() { mousepoint=0; float d=PP[0].disToMouse(); for (int i=1; i