class Tree { ArrayList tree = new ArrayList(); float rootx; float rooty; float rootangle; float branchsize; int maxL; /////////////////////////////////////////////////////////////////////////////////////// //GENERATE + RENDER FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////// Tree(float rx_, float ry_, float ra_, float bs_, int mL) { rootx=rx_; rooty=ry_; rootangle=ra_; branchsize=bs_; maxL=mL; branch(-1, rootx, rooty, branchsize, rootangle, 1, maxL); childinfo(); } 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(); }//END regenerate void render() { float x, y; stroke(255); for(int i=0; i= 0) { Node n2= (Node) tree.get(n.getPARENT()); n.setRX(n2.returnx()); n.setRY(n2.returny()); } } childinfo(); }//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)); } 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; i90) { n.setA(n.getA()+random(-5,5)); } }//END angleshake() void levelshake(int i) { Node n= (Node) tree.get(i); if(n.getLEVEL()>4) { n.setA(n.getA()+random(-5,5)); } }//END levelshake() void swingtree(float angle) { Node n= (Node) tree.get(0); n.setA(angle); alterchildrenangle(n, angle); } }//END Tree