//***************************************************************************** // Polyloop editor + Js refinement, Jarek Rossignac, Feb 2007 //***************************************************************************** boolean showHelpText=true; int[] X = {1,1,0,-1,-1,0}; int[] Y = {0,1,1,0,-1,-1}; int k=0,e=0; int s=60; int[][] S = { {3,3,3,1,3,3,2,3,3,3,3,3,1,3,3,2,3,3}, {2,2,3,2,2,3,2,2,3}, {1,5,3,3,1,2,3,3,3,3,3,1,3,3,2,2,4}, {0,2,3,2,2,3,2,3,3,3,2,2,3,2,3,3,3,2,2,2,2,4,3,4,5,3,3,4,5,3}, {2,4,5,3,4,2,2,2,2,3,3,3,2,2,3,2,3,3,3,2,2,3,2,3,3,3,2,2,3,2,3,3,3,2,2,2,2,4,3,4,5,3,3,4,5,3,3}, {2,3,3,2,2,2,2,4,3,1}, {2,2,2,3,2,3,3,3,3,2,2,3,2,3,3,3,3,2,2,3,2,3,3,3,3,2,2,2,2,4,3,3,4,5,3,3,4,5,3,3,4,5,1}, // flip {1,5,1,2,2,2,2}, // good, 0 internal {3,3,3,1,2,3,3,3,2,1,3}, // good strip {3,3,3,1,2,3,3,3,3,3,1,3,3,3,2,3,3,3,3,1,3,3,3,3,3,2,1,3,3,3,3,5,3,4,3,5}, // goof self overlap {2,3,2,2,2,4,1,4,1,3}, // good, 2 internals {3,4,3,2,2,2,3,2,3,3,3,3,2,2,3,2,3,3,3,3,2,2,3,2,3,3,3,3,2,2,3,2,3,3,3,3,2,2,2,2,4,3,3,4,5,3,3,4,5,3,3,4,5,3}, // good tricky loop {2,1,3,2,2,2,3,3,1,3,2,2,1}, // bad 2 turns {1,5,1,2,2,2,3}, // bad open {2,4,5,3,4,2,2,2,2,3,3,3,2,2,3,2,3,3,3,2,2,3,2,3,3,3,2,2,3,2,3,3,3,2,2,2,2,4,3,4,5,3,3,4,5,3,3,4,5,3,3,4,5,3,3}, }; pt PP = new pt(0,0); int mm=0; color red, yellow, green, cyan, blue, magenta, dred, dyellow, dgreen, dcyan, dblue, dmagenta, white, black, orange, grey, metal; void setup() { size(800, 800); strokeCap(SQUARE); //smooth(); colorMode(HSB,121); red = color(0, 120, 120); yellow = color(20, 120, 120); green = color(40, 120, 120); cyan = color(60, 120, 120); blue = color(80, 120, 120); magenta = color(100, 120, 120); dred = color(0, 120, 60); dyellow = color(20, 120, 60); dgreen = color(40, 120, 60); dcyan = color(60, 120, 60); dblue = color(80, 120, 60); dmagenta = color(100, 120, 60); white = color(0, 0, 120); black = color(0, 120,0); grey = color(0, 120,60); orange = color(10, 100, 120); metal = color(70, 60, 100); // strokeJoin(ROUND); strokeCap(ROUND); PFont font = loadFont("Courier-14.vlw"); textFont(font, 13); if(!found1()) found222(); printS(); reset(); } void reset() {PP.setTo(width/2,height/2); mm=0;} void draw() { background(121); noFill(); if (showHelpText) {showHelp();} else { strokeWeight(1); stroke(metal); drawGrid(); int b=S[k].length; if(b>0) { int t=trianglesIn(S[k]); int v=(b+t)/2+1-b; int w=turns(S[k]); fill(black); String D="It has "+str(t)+" triangles, and "+str(b)+" border and "+str(v)+" internal vertices. e="+str(e)+". m="+str(mm)+". "+str(w)+" turns"; text(D,20,60); D="At gate "+e+" you can safely "; if(canDeleteVertex(e,S[k])) D=D+"delete the start vertex "; else if (canBreakEdge(e,S[k])) D=D+"split the edge"; else D=D+"do nothing"; text(D,20,80); D = "S["+str(k)+"]=("; for(int i=0; ixy) {xy=x+y; found=true; e=i;}; }; println("xy="+xy); return(found); } void breakEdge(int e) {int L = S[k].length; int ne=(e+1)%L; S[k][e]--; S[k][ne]--; if(ne==0) { mm=(mm+5)%6; S[k]=splice(S[k],5,L); }; if(e==0) { mm=(mm)%6; S[k]=splice(S[k],5,ne); }; if((e!=0)&&(ne!=0)) S[k]=splice(S[k],5,ne); }; void deleteVertex(int e) { int L = S[k].length; int ne=(e+1)%L; int pe=(e+L-1)%L; println("ne="+ne); if(e==0) { PP=getPoint(S[k],ne); mm=(mm+1)%6; }; if(ne==0) { PP=getPoint(S[k],ne); mm=(mm-1)%6; }; S[k][pe]--; S[k][ne]--; if(e0) {String SS="{"+str(S[k][0]); for(int i=1; i') {k=(k+1)%S.length; if(!found1()) found222(); reset(); }; if (key=='<') {k=(k+S.length-1)%S.length; if(!found1()) found222(); reset(); }; if (key=='.') e=(e+1)%S[k].length; if (key==',') e=(e+S[k].length-1)%S[k].length; if(L>0) printS(); } void next () { if(!found1()) if(!found222()) found2m(); };