class Tree { ArrayList tree = new ArrayList(); float rootx; float rooty; float rootangle; float branchsize; int maxL; int currentmaxL; int strokeC; /////////////////////////////////////////////////////////////////////////////////////// //GENERATE + RENDER FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////// Tree(float rx_, float ry_, float ra_, float bs_, int mL, int strokeC_) { rootx=rx_; rooty=ry_; rootangle=ra_; branchsize=bs_; maxL=mL; strokeC=strokeC_; branch(-1, rootx, rooty, branchsize, rootangle, 1, maxL); childinfo(); currentmaxL=0; } void branch(int p, float rx, float ry, float d, float a, int L, int MAXL) { float nx, ny; int indexhold; if(L < MAXL) { //Calculate and draw branch nx=rx+d*cos(-1*radians(a)); ny=ry+d*sin(-1*radians(a)); //Add to Arraylist indexhold=tree.size(); tree.add(new Node(L, indexhold, p, rx, ry, a, d)); //Recurse branch(indexhold, nx, ny, d*.7, a+random(10,25), L+1, MAXL); branch(indexhold, nx, ny, d*.7, a-random(10,25), L+1, MAXL); } }//END branch void singlebranch(int p, float rx, float ry, float d, float a, int L) { int indexhold; //Add to Arraylist indexhold=tree.size(); tree.add(new Node(L+1, indexhold, p, rx, ry, a, d)); }//END singlebranch void regenerate() { tree.clear(); branch(-1, rootx, rooty, branchsize, rootangle, 1, maxL); childinfo(); currentmaxL=0; }//END regenerate void render() { float x, y; stroke(strokeC); for(int i=0; i= 0) { Node n2= (Node) tree.get(n.getPARENT()); n.setRX(n2.returnx()); n.setRY(n2.returny()); } if(n.getLEVEL() > maxL) { maxL=n.getLEVEL(); } } childinfo(); currentmaxL=maxL; println(currentmaxL); }//END update void childinfo() { //println(tree.size()); for(int i=0; i= 0 && n.getCONNECTED()==false) { Node n2= (Node) tree.get(n.getPARENT()); n2.addCHILD(n.getME()); n.setCONNECTED(true); } } } void alterchildrenangle(Node parent, float adiff) { for(int i=0; i < parent.getCHILDSIZE(); i++) { Node nc= (Node) tree.get(parent.getCHILD(i)); nc.setA(nc.getA()-adiff); alterchildrenangle(nc, adiff); } }//END alterchilderangle //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PRESSED FUNCTION //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int pressed(int caughti, float x, float y) { float initiala; float adiff; boolean onecaught=false; int caught=-1; if(caughti == -1) { for(int i=0; i -1; i=i-1)//may have to go backwards { deletebranch(n.getCHILD(i)); } } } void deletebranch(int nodei) { Node n= (Node) tree.get(nodei); for(int i=n.getCHILDSIZE()-1; i > -1; i=i-1)//may have to go backwards { deletebranch(n.getCHILD(i)); } moveback(nodei); tree.remove(nodei); }//END deletebranch void moveback(int nodei) { //HERE this is absurd but: we search the entire structure to reset anything above the target //we also delete any references to this index except for parent references since these will be //deleted anyways for(int i=0; i < tree.size(); i++) { Node n= (Node) tree.get(i); //remove and decrement any child references for(int j = n.getCHILDSIZE()-1; j > -1; j--) { if(n.getCHILD(j) > nodei) { n.setCHILD(j, n.getCHILD(j)-1); } if(n.getCHILD(j)==nodei) { n.removeCHILD(j); j--;//pretty sure this belongs here } } //decrement any parent references if(n.getPARENT() > nodei) { n.setPARENT(n.getPARENT()-1); } //if i > nodei decrement self reference if(n.getME() > nodei) { n.setME(n.getME()-1); } } }//END moveback /////////////////////////////////////////////////////////////////////////////// //Node Control FUNCTIONS /////////////////////////////////////////////////////////////////////////////// void controltree(int arg, int shakepiece) { for(int i=0; i4) { n.setA(n.getA()+random(-5,5)); } }//END levelshake() //5 void shrink1(int i) { Node n= (Node) tree.get(i); n.setA(n.getA()+random(-1,1)); n.setD(n.getD()*random(.95,1.05)+3*sin(radians(millis()/20)));// Changing these makes tree shrink or grow }//END shrink() //6 void shrink2(int i) { Node n= (Node) tree.get(i); n.setD(n.getD()+1*sin(radians(millis()/20)));// Changing these makes tree shrink or grow }//END shrink() //7 void shrink3(int i) { Node n= (Node) tree.get(i); //6 LOOKS PISSED OFF/PANTING KEEP n.setD(abs(n.getD()+75/n.getD()*sin(radians(millis()/(1+n.getLEVEL()/5)))));// Changing these makes tree shrink or grow }//END shrink() //8 void shrink4(int i) { Node n= (Node) tree.get(i); //7 KEEP n.setD(abs(n.getD()+4*sin(radians(millis()/(1+n.getME()%20)))));// Changing these makes tree shrink or grow }//END shrink() //9 void sway1(int i, int shakepiece)//NEEDS TO BE A SWAY THAT DEALS WITH CHILDREN TOO { Node n= (Node) tree.get(i); if(n.getLEVEL()==shakepiece) { //1 KEEP if(n.getLEVEL()>1) { n.setA(n.getA()+random(-10*float(n.getLEVEL()),float(n.getLEVEL()))); } } }//END sway() //10 void sway2(int i, int shakepiece)//NEEDS TO BE A SWAY THAT DEALS WITH CHILDREN TOO { Node n= (Node) tree.get(i); n.setA(n.getA()+20/float(n.getLEVEL())*sin(radians(millis()/n.getLEVEL()))); }//END sway() //BELLOW ARE OLD void shrink(int i) { Node n= (Node) tree.get(i); //1 NAH //n.setA(n.getA()+random(-1,1)); //n.setD(n.getD()+random(-5,5));// Changing these makes tree shrink or grow //2 //n.setD(n.getD()*random(.95,1.05)+3*sin(radians(millis()/20)));// Changing these makes tree shrink or grow //3 KEEP //n.setA(n.getA()+random(-1,1)); //n.setD(n.getD()*random(.95,1.05)+3*sin(radians(millis()/20)));// Changing these makes tree shrink or grow //4 KEEP //n.setD(n.getD()+1*sin(radians(millis()/20)));// Changing these makes tree shrink or grow //5 //n.setD(n.getD()+2*sin(radians(millis()/(1+n.getLEVEL()))));// Changing these makes tree shrink or grow //6 LOOKS PISSED OFF/PANTING KEEP //n.setD(abs(n.getD()+75/n.getD()*sin(radians(millis()/(1+n.getLEVEL()/5)))));// Changing these makes tree shrink or grow //7 KEEP // n.setD(abs(n.getD()+4*sin(radians(millis()/(1+n.getME()%20)))));// Changing these makes tree shrink or grow }//END shrink() void sway(int i, int shakepiece)//NEEDS TO BE A SWAY THAT DEALS WITH CHILDREN TOO { Node n= (Node) tree.get(i); if(n.getLEVEL()==shakepiece) { //1 KEEP if(n.getLEVEL()>1) { // n.setA(n.getA()+random(-10*float(n.getLEVEL()),float(n.getLEVEL()))); } //2 (AND OR) //n.setA(n.getA()+20/float(n.getLEVEL())*sin(radians(millis()))); } //3 KEEP n.setA(n.getA()+20/float(n.getLEVEL())*sin(radians(millis()/n.getLEVEL()))); }//END sway() void angleshake(int i) { Node n= (Node) tree.get(i); if(n.getA()>90) { n.setA(n.getA()+random(-5,5)); } }//END angleshake() void swingtree(float angle) { Node n= (Node) tree.get(0); n.setA(angle); alterchildrenangle(n, angle); } }//END Tree