int count =8; // 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 soft = color(200, 200, 210); 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); int gr=1; // current maximum for recursion calls float[] tt = new float [7]; // values ot Jarek's offset for each recursion boolean dots = true; float s=0.20; //float t=sqrt(2.0*s/3.0); float t=s+0.01; void setup() { size(600, 600); // framerate(30); 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; ibx) {bx=P[i].x;}; if (P[i].xby) {by=P[i].y;}; if (P[i].yabs(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; i600)||(y<0)||(y>600)));}; void label(String s, vec D) {text(s, x+D.x,y+D.y); }; vec vecTo(pt P) {return(new vec(P.x-x,P.y-y)); }; float disTo(pt P) {return(sqrt(sq(P.x-x)+sq(P.y-y))); }; vec vecToMid(pt P, pt Q) {return(new vec((P.x+Q.x)/2.0-x,(P.y+Q.y)/2.0-y)); }; vec vecToProp (pt B, pt D) { vec CB = this.vecTo(B); float LCB = CB.norm(); vec CD = this.vecTo(D); float LCD = CD.norm(); vec U = CB.make(); vec V = CD.make(); V.sub(U); V.mul(LCB/(LCB+LCD)); U.add(V); return(U); }; } class vec { float x,y; vec (float px, float py) {x = px; y = py;}; vec make() {return(new vec(x,y));}; void show (pt P) { ellipse(P.x, P.y, 3, 3); line(P.x,P.y,P.x+x,P.y+y); }; void add(vec V) {x += V.x; y += V.y;}; void sub(vec V) {x -= V.x; y -= V.y;}; void mul(float m) {x *= m; y *= m;}; void write() {println("("+x+","+y+")");}; float norm() {return(sqrt(sq(x)+sq(y)));}; void unit() {float n=sqrt(sq(x)+sq(y)); if (n>0.0001) {x/=n; y/=n;};}; void left() {float w=x; x=-y; y=w;}; void back() {x= -this.x; y= -this.y;}; } pt midPt(pt A, pt B) {return(new pt((A.x+B.x)/2,(A.y+B.y)/2)); }; vec midVec(vec U, vec V) {return(new vec((U.x+V.x)/2,(U.y+V.y)/2)); }; float dot(vec U, vec V) {return(U.x*V.x+U.y*V.y); };