void setup () { size(400, 400); frameRate(30); } int maxIterations = 100; int iterationNum = int(random(5,maxIterations)); float[] seeds = new float[maxIterations]; // Create new plant every time the user clicks void mouseReleased() { iterationNum = int(random(5,maxIterations)); for (int p = iterationNum; p > 0; p--) { seeds[p-1] = random(2*PI); } } void draw() { background(200); float rot = 1.5*PI; // Set the initial rotation float tranX = 10; // Define the length of the plant bits float tranY = 0.0; translate(width/2, height*0.75); // Move the plant closer to middle pushMatrix(); //Start drawing the plant for (int i = iterationNum; i > 0; i = i-1) { popMatrix(); rotate(rot); translate(tranX, tranY); pushMatrix(); //set the appearance of the line strokeWeight(map (i, 0, iterationNum, 1, 5)); stroke(map (i, 0, iterationNum, 0, 190)); // smooth(); // float strokeAlpha = map (i, 0, iterationNum, 255, 128); // stroke (0, strokeAlpha); line(0, 0 , -tranX, 0); rot = sin(seeds[i-1]) * map(mouseY, 0, height, 0.78, 1.02); //Modify the twist of the plant popMatrix(); // Grow leaves if(seeds[i] + i > 9) { fill(0, 128); noStroke(); ellipse(0, 0, constrain(i * 1.2 + 4, 0, 15), 4); } // Grow flower if(i == 1) { fill(255, 190); noStroke(); //rect(0, -10, 20, 20); triangle(-5, 0, 15, 7, 15, -7); ellipse(25, 0, 10, 10); } pushMatrix(); } //End drawing the plant popMatrix(); }