ArrayList reverse
in
Programming Questions
•
7 months ago
I can't figure out why my tree won't reverse. After it grows I want it to disappear in the opposite direction. Code is Daniel Shiffmans tree example and I used his Branch class.
-
ArrayList a;
float r= random (1,5);boolean remove=false;boolean finish=false;
void setup() {size(600,600);background(255);smooth();// Setup the arraylist and add one branch to ita = new ArrayList();
Branch b= new Branch (new PVector (100, 300), new PVector (0.5f,-0.5f),300);// Add to arraylist
a.add(b);}
void draw() {strokeWeight(.3f);stroke(0);
for (int i = a.size()-1; i >= 0; i--) {// Get the branch, update and draw itBranch b = (Branch) a.get(i);b.update();b.render();// If it's ready to splitif (b.timeToBranch()) {a.remove(i); // Delete ita.add(b.branch( 40f)); // Add one going righta.add(b.branch(-40f)); // Add one going lefta.add(b.branch(-70f));a.add(b.branch(50f));// strokeWeight(100/a.size(1));}}
if (a.size()>=200)remove =true;
if (a.size()>=1) {if (remove) {for(int i=a.size()-1; i>=0; i++) {//a.remove(i);}
}}}
1