// Written by Jarek Rossignac, Georgia Tech, Sept 2005. int count =5; // number of control vertices pt[] P = new pt [count]; // control vertices int bi=-1; // index of selected vertex, -1 if none selected pt Mouse = new pt(0,0); // current mouse position color red = color(200, 10, 10); color blue = color(10, 10, 200); color green = color(10, 200, 20); color black = color(10, 10, 10); color magenta = color(250, 150, 200); vec a,b,c; // cubic coeffs float tt; // parameter of the point C on the cubic boolean straight = false; // toggled with "c" for making the fit independent of C pt BF; void setup() { size(600, 600); for (int i=0; i10) { // if closest vertex is too far bd=600; // reinitilize distance squared for (int i=0; ibi; i--) {P[i+1].setTo(P[i]);}; // shift down the rest bi++; P[bi].setTo(Mouse); count++; // insert new vertex at mouse position } else {bi=-1;}; // nothing selected }; } float d2(int j) {return (Mouse.disTo(P[j]));}; // squared distance from mouse to vertex P[i] float dm(int j) {return (Mouse.vecToMid(P[j],P[in(j)]).norm());}; void mouseReleased() { // do this when mouse released if ( (bi!=-1) && P[bi].isInWindow() ) { // if outside of port for (int i=bi; iabs(P[in(i)].y-P[i].y)) {float dy=(P[in(i)].y-P[i].y)/2; P[in(i)].y-=dy; P[i].y+=dy;} else {float dx=(P[in(i)].x-P[i].x)/2; P[in(i)].x-=dx; P[i].x+=dx;} }; }; }; //************************************** //**** utilities for polyloops //************************************** int in(int j) { if (j==count-1) {return (0);} else {return(j+1);} }; // next vertex in control loop int ip(int j) { if (j==0) {return (count-1);} else {return(j-1);} }; // next vertex in control loop void writePts() { for (int i=0; i