//import processing.opengl.*; int numBranches = 900; Branch[] plant = new Branch[numBranches]; float warble = 0.013; int counter = 0; float x_next; float y_next; void setup () { size(800, 800); framerate(30); colorMode(RGB, 1.0); background(0); //noStroke(); x_next = 0; y_next = 0; for( int i = 0; i < numBranches; i++ ) { plant[i] = new Branch(x_next, y_next, random(1.75*PI), 10, 1); plant[i].calcEnd(); x_next = plant[i].x_end; y_next = plant[i].y_end; } } void draw () { //background(0); fill(0, 0.65); noStroke(); rect(0, 0, width, height); stroke(1); pushMatrix(); translate(width/2, height/2); int whichBranch = counter % numBranches; plant[whichBranch] = new Branch(x_next, y_next, random(360), 20, 1); x_next = 0; y_next = 0; for( int i = 0; i <= whichBranch; i++ ) { plant[i].x = x_next; plant[i].y = y_next; plant[i].c = 0.2 + 0.8*float(i)/float(whichBranch); plant[i].rot += random(-warble, warble); plant[i].place(); plant[i].calcEnd(); x_next = plant[i].x_end; y_next = plant[i].y_end; /*plant[i].rot += random(warble*-1, warble); plant[i].calcEnd(); x_next = plant[i].x_end; y_next = plant[i].y_end;*/ } popMatrix(); counter++; } class Branch { float x; float y; float rot; float len; float c; float x_end; float y_end; Branch( float _x, float _y, float _rot, float _len, float _c ) { x = _x; y = _y; rot = _rot; len = _len*2; c = _c; } void place() { pushMatrix(); translate(x, y); stroke(c); rotate(rot); line(0, 0, len, 0); popMatrix(); } void calcEnd() { x_end = x + cos(rot)*len; y_end = y + sin(rot)*len; } }