//***************************************************************************** // Polyloop editor + smoothing + subdivision + uniform sampling, Jarek Rossignac, August 2006 //***************************************************************************** int vn =6; // number of control vertices int xvn, svn=vn; // number of new vertices int cap=256; // size of control vetices arrays int scap=cap*2*2*2*2*2*2; // size of computed vertices array pt[] P = new pt [cap]; // vertices of the control polyloop pt[] C = new pt [scap]; // verticves of the computed polyloop vec[] CL = new vec [scap]; // laplace vectors for the computed vertices float tuck=0.5, untuck=1.0, tuckChange=0.125; // fraction of laplace vector for tuck, untuck, and the increment for changing them 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 color soft = color(250, 230, 140), red = color(200, 10, 10), blue = color(10, 10, 200), green = color(0, 150, 0); color black = color(10, 10, 10), magenta = color(250, 150, 200), brown = color(100, 50, 20), yellow = color(250, 250, 20); boolean dots = true, numbers = false, laplace=false; // toggles display of dots and numbers boolean saveNew = false; // toggles between saving control polygon or new polygon boolean samples = false; // true to show samples as dots boolean move = false; // true when animation int ai=0; // index of moving dot void setup() { size(600, 600); // initialization PFont font = loadFont("Courier-14.vlw"); textFont(font, 12); 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].setFromPt(P[i]);}; // shift down the rest bi++; P[bi].setFromMouse(); vn++; // insert new vertex at mouse position println("inserted vertex "+bi); } 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') {tuck+=tuckChange; println("tuck = "+int(tuck*8)+"/8"); }; if (key=='<') {tuck-=tuckChange; println("tuck = "+int(tuck*8)+"/8"); }; if (key=='+') {untuck+=tuckChange; println("untuck = "+int(untuck*8)+"/8"); }; if (key=='-') {untuck-=tuckChange; println("untuck = "+int(untuck*8)+"/8"); }; if (key=='p') {dots=!dots;}; if (key=='P') {laplace=!laplace;}; if (key=='n') {numbers=!numbers;}; if (key=='w') {writePts();}; if (key=='W') {writeNewPts();}; if (key=='s') {xvn=vn; saveNew=false; savePts(); }; if (key=='S') {xvn=svn; saveNew=true; savePts(); }; if (key=='l') {loadPts();}; if (key=='i') {saveFrame("pix-####.tif");}; 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;} }; }; if (key=='h') { float sx=width; float sy=height; float bx=0.0; float by=0.0; for (int i=0; ibx) {bx=P[i].x;}; if (P[i].xby) {by=P[i].y;}; if (P[i].y