int count =4; // number of control vertices int cap=128; // size of control arrays pt[] P = new pt [cap]; pt[] SP = new pt [cap]; vec[] LP = new vec [cap]; int bi=-1; // index of selected vertex, -1 if none selected pt Mouse = new pt(0,0); // current mouse position pt Last = new pt(0,0); // clast point color grey = color(200, 200, 210); color red = color(200, 10, 10); color blue = color(10, 10, 200); color lightblue = color(100, 100, 255); color green = color(10, 200, 20); color black = color(10, 10, 10); color magenta = color(250, 150, 200); boolean dots = true; float d = 100.0, dd=200.0; pt eye = new pt(-d,0); boolean firstTime = true; float tt; boolean straight = false; void setup() { size(900, 400); // framerate(30); P[0]=new pt(-d,0.0); for (int i=1; 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 bi= -1; }; //********************************** //*** CONTROL WITH KEYS //********************************** void keyPressed() { if (key=='c') {straight=!straight;}; if (key=='w') {writePts();}; if (key=='s') {savePts();}; if (key=='l') {loadPts();}; if (key=='a') { // axis aligns the edges for (int i=0; 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