class Bamboo{ float xpos; float ypos; float speed; float thickness; float fillColor; int direction; float slope; float bambooColor; float joint; int counter; int branchCounter; Bamboo(){ xpos = random(width); speed = 3.0f; thickness = random(30,60); ypos = height+thickness; fillColor = random(100); direction = 0; slope = 0.1; bambooColor = 10; joint = random(30,height-30); counter = 0; branchCounter = 0; } void update(){ ypos -= speed; if (ypos<0) { ypos=height; xpos = random(width); thickness = random(30,70); slope = random(-0.5, 0.5); bambooColor = random(3,10); joint = random(30,height-30); counter = 0; branchCounter =0; } if (ypos < joint){ counter = counter +1; if (counter < random(2)){ bambooJoint(); if(thickness>50){ leaves(); } else{ leaves2(); } } } } void display(){ fill(0, bambooColor); noStroke(); float f1 = 0.0; beginShape(POLYGON); while(f1 < TWO_PI) { vertex(xpos + cos(f1)*(27-thickness) + random(0,5), ypos + sin(f1)*(27-thickness) + random(0,5)); f1 += PI/12.0; } endShape(); xpos += slope; thickness -= 0.05; branchCounter = branchCounter + 1; } void bambooJoint(){ float f1 = 0.0; float jointThickness = thickness - (0.05*branchCounter); fill(255,255,255,bambooColor+10); beginShape(POLYGON); while(f1 < TWO_PI) { vertex(xpos + cos(f1)*(27-jointThickness) + random(0,5), ypos + sin(f1)*(27-jointThickness) + random(0,5)); f1 += PI/12.0; } endShape(); } void leaves(){ float leaveSize = random(1,3); fill(87,120,54,thickness-10); noStroke(); for (int i = 0; i < random(3); i++) { pushMatrix(); translate(xpos,ypos); rotate(random(PI/4)); ellipseMode(CORNER); ellipse(0+thickness*0.75,0,thickness,10); rotate(random(PI/2)+PI/2); ellipseMode(CORNER); ellipse(0+thickness*0.5,0,thickness,10); popMatrix(); } } void leaves2(){ float leaveSize = random(1,3); fill(87,120,54,thickness-10); noStroke(); for (int i = 0; i < random(3); i++) { pushMatrix(); translate(xpos+thickness*0.25,ypos); rotate(random(PI/4)); ellipseMode(CORNER); ellipse(0,0,thickness,10); rotate(random(PI/2)+PI/2); ellipseMode(CORNER); ellipse(0+thickness/2,0,thickness,5); popMatrix(); } } }