//***************************************************************************** // Polyloop morph using Minkowski average, Jarek Rossignac, Oct 2006 //***************************************************************************** int nP=3, nQ=32, nPQ; // numbers of vertices in the two curves int cap=64; // max number of vertices pt[] P = new pt [cap]; // vertices of the editable curve pt[] Q = new pt [cap]; // vertices of the other curve pt[] PQ = new pt [cap]; // vertices of the other curve int bi=-1; // index of selected mouse-vertex, -1 if none selected pt Mouse = new pt(0,0); // current mouse position pt Last = new pt(0,0); // last point drawn float t=0.0, dt=0.02; // current time amd time increment color red = color(200, 10, 10), blue = color(10, 10, 200), green = color(0, 150, 0); // COLORS boolean showDots=true; void setup() { size(500, 500); // open window for (int i=0; i=1)||(t<=0)) dt=-dt; } else { int n=10; float dt=1.0/float(n); for (t=dt; t<1; t+=dt) {stroke(int(255*t),int(255*(1.0-t)),0); drawMorph(); }; }; // draw morph using both colors }; void drawCurve(pt[] P, int nP) {beginShape(); for (int i=0; i 0) // if AB.left * DC <0 (y is down, so left is reversed) && (dot(C.vecTo(D).left(),C.vecTo(E)) > 0) // skip concave vertices && (dot(A.vecTo(B).left(),D.vecTo(E)) > 0) ) // and if AB.left * DE <0 morph(A,B,D,t); // morph edge(A,B) of P with vertex D of Q }; }; for (int i=0; i 0) && (dot(C.vecTo(D).left(),C.vecTo(E)) > 0) // skip concave vertices && (dot(A.vecTo(B).left(),D.vecTo(E)) > 0) ) morph(A,B,D,1-t); // morph vertex D of P with edge(A,B) of Q }; }; }; void morph (pt pA, pt pB, pt C, float t) {pt A=pA.make(); A.moveTowards(C,t); pt B=pB.make(); B.moveTowards(C,t); A.showLineTo(B);}; //void copyPts () {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); nP++; // 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[j] float dm(int j) {return (Mouse.disTo(average(P[j],P[in(j)])));}; // squared distance from mouse to mid-edge point void mouseReleased() { // do this when mouse released if ( (bi!=-1) && P[bi].isOut() ) { // if outside of port for (int i=bi; i