import traer.physics.*; Graph myGraph; ParticleSystem physics; int counter; ArrayList hairList; float scale = 1; float centroidX = 0; float centroidY = 0; Node[] all; int retimer = 40; int n; boolean go; ArrayList gridList; ArrayList groundList; ArrayList shellList; ArrayList trackList; PVector[] form; Node[] hairs; int ct; Node[] cycles; int lCount; int timer; int formCt; int parts = 12; String[] formList = { "ground", "shell", "track"}; String[][] sproutSeq; String[][] convergeSeq; String seqName; Node[] clickList = new Node[0]; void setup(){ size(600 ,450, P3D); randomSeed(134); physics = new ParticleSystem(0,0,-1.0, 1.5); myGraph = new Graph( physics ); hairList = new ArrayList(); counter = 0; n=0; gridList = new ArrayList(); cycles = new Node[0]; ct = 0; lCount = 1; formCt = 0; form = loadForm(formList[0], 1.0); groundList = new ArrayList(Arrays.asList(form)); PVector[] tempForm = loadForm(formList[1], 1.0); shellList = new ArrayList(Arrays.asList(tempForm)); form = concat(form,tempForm); tempForm = loadForm(formList[2], 1.0); trackList = new ArrayList(Arrays.asList(tempForm)); form = concat(form,tempForm); //some sprouting sequence of a b c sproutSeq = someSequence(100, parts+1, 6); //82 convergeSeq = someSequence(67, 3, 2); //80 webify4(form, null, 140, parts); } void draw(){ background(0); float camLen = 200; camera( sin(radians(frameCount/10.0))*(camLen), cos(radians(frameCount/10.0))*(camLen), camLen * .8 , 0,0,0, 0.0,0.0,-1.0); physics.tick(.1); background(200); // GRID stroke(160); for(int i=-200; i<=200; i+=25){ for(int j=-200; j<=200; j+=25){ line(-200, j, 200, j); line(i, -200, i, 200); } } stroke(120); for(int i=-200; i<=200; i+=50){ for(int j=-200; j<=200; j+=50){ line(-200, j, 200, j); line(i, -200, i, 200); } } stroke(80); strokeWeight(2); noFill(); rect(-200,-200,400,400); line(-200,0,200,0); line(0,-200,0,200); strokeWeight(1); timer = frameCount; float touchThresh = 20; stroke(255,40); for(int j=0; j 0 && retimer < 0){ webify4(form, clickList, 1, parts); clickList = new Node[0]; retimer = 20; } for(int i=0; i< all.length; i++){ if(all[i].type != "x" && all[i].type != "g"){ all[i].avoid(all); } } for(int i=0; i< 4; i++){ all[(int)random(all.length)].convergeMultiple(); } for(int i=0; i< 40; i++){ // all[(int)random(all.length)].torque(); } all[(int)random(all.length)].tieEnds(); myGraph.update(); myGraph.plot3D( 0.5); strokeWeight(3); for(int i=0; i< form.length; i++){ point(form[i].x, form[i].y, form[i].z); } strokeWeight(1); } ArrayList subDivide(PVector s, PVector e, int seg){ ArrayList pts = new ArrayList(); pts.add(s); PVector dir = PVector.sub(e, s); float len = dir.mag(); dir.normalize(); dir.mult(len/seg); for(int i=0; i 5){ cont = false; } } else{ s = scopeOut[floor(random(scopeOut.length))]; } if(choiceB == 0 && cont == true){ end = scopeIn[floor(random(scopeIn.length))]; e = end.pv; if(end.connections.length > 2){ cont = false; } } else{ e = scopeOut[floor(random(scopeOut.length))]; for(int j=0; j< all.length; j++){ if(all[j].pv == e){ cont = false; s = new PVector(); e = new PVector(); break; } } } if(cont == true && PVector.dist(s,e) <= 200.0 && abs(s.z - e.z) > 40){ //300 if(choiceA == 1){ start = myGraph.addNode(counter+"", 3, s.x,s.y,s.z); counter++; if(groundList.contains(s) == true){ start.type = "c"; } else if(shellList.contains(s) == true){ start.type = "a"; } else if(trackList.contains(s) == true){ start.type = "b"; } start.fix(); } if(choiceB == 1){ end = myGraph.addNode(counter+"", 3, e.x,e.y,e.z); counter++; if(groundList.contains(e) == true){ end.type = "c"; if(start.type == "c" && start.p.isFixed() == true){ cont = false; } } else if(shellList.contains(e) == true){ end.type = "a"; } else if(trackList.contains(e) == true){ end.type = "b"; if(start.type == "c" && start.p.isFixed() == true){ cont = false; } } end.fix(); } } else{ cont = false; } if(cont == true){ int order = 0; if((start.type == "a" || end.type == "a") && (start.type == "a" || end.type == "a")){ order = 0; } else if((start.type == "a" || end.type == "a") && (start.type == "b" || end.type == "b")){ order = 1; } else if((start.type == "a" || end.type == "a") && (start.type == "c" || end.type == "c")){ order = 2; } else if((start.type == "b" || end.type == "b") && (start.type == "b" || end.type == "b")){ order = 3; } else if((start.type == "b" || end.type == "b") && (start.type == "c" || end.type == "c")){ order = 4; } else if((start.type == "c" || end.type == "c") && (start.type == "c" || end.type == "c")){ order = 5; } ArrayList l = subDivide(s,e,segs); Node last; Node c; Node[] all; for(int j=1; j< l.size()-1; j++){ PVector b = (PVector)l.get(j); if(j == 1){ last = start; c = myGraph.addLeaf(counter+"", last, 3, b.x, b.y, b.z); counter++; c.type = sproutSeq[order][j-1]; } else if(j>1 && j< l.size()-2){ all = myGraph.getNodes(); last = all[all.length-1]; c = myGraph.addLeaf(counter+"", last, 3, b.x, b.y, b.z); counter++; c.type = sproutSeq[order][j-1]; } else{ all = myGraph.getNodes(); last = all[all.length-1]; myGraph.connectNodes(last, end); } } } } } PVector[] loadForm(String file, float scaleFactor){ PVector[] formPts = new PVector[0]; String[] data = loadStrings(file+".txt"); for(int i=0; i < data.length; i++){ if(data[i].contains("ON_Point:")){ String[] records = split(data[i], "|"); for(int j=0; j < records.length; j++){ if(records[j].contains("ON_Point:") == false && records[j].equals("") == false){ String[] pts = split(records[j], ","); PVector tempPt = new PVector(float(pts[0])*scaleFactor, float(pts[1])*scaleFactor, float(pts[2])*scaleFactor); println(tempPt.y); tempPt.x = map( tempPt.x, -270,250,-200,200); tempPt.y = map( tempPt.y, -24,380,-200,200); if(tempPt.z < 120){ gridList.add(tempPt); formPts = (PVector[]) append( formPts, tempPt); } } } } } return formPts; } PVector[] concat(PVector[] A, PVector[] B) { PVector[] C= new PVector[A.length+B.length]; System.arraycopy(A, 0, C, 0, A.length); System.arraycopy(B, 0, C, A.length, B.length); return C; } String[][] someSequence(int rs, int seqLen, int times){ int arrayLength = 3; Random generator = new Random( rs ); String[][] seq = new String[times][seqLen]; for(int i=0; i