// PB_21_14_2 // nofLeaves and sizeLeaves are mouse controlled pars int x = 30; // x loc of first piece int nofLeaves = 12; // nof leaves int sizeLeaves = 10; // size of leaves int nofPieces = 6; // how many to draw void setup() { size(200, 200); stroke(0, 255, 0, 200); fill(0, 255, 0, 200); smooth(); noLoop(); } void draw() { background(0); // println("2. drawStems called"); for (int j=0; j< nofPieces; j++) { vine(x, nofLeaves, sizeLeaves); x+= 30; } } void vine(int x, int numLeaves, int leafSize ) { stroke(0, 255, 0, 200); line(x, 0, x, height); noStroke(); int gap = height / numLeaves; // Calculate average leaf gap int leafSizeX = leafSize; int leafSizeY = leafSize; for (int i = 0; i < numLeaves; i++) { leaf(x, i * gap + random(gap), leafSizeX, leafSizeY); leafSizeX = -leafSizeX; // Flip leaf direction } } void leaf(float x, float y, float sizeX, float sizeY) { pushMatrix(); translate(x, y); // Move to position scale(sizeX, sizeY); // Scale to size beginShape(); // Draw the shape vertex(1.0, -0.7); bezierVertex(1.0, -0.7, 0.4, -1.0, 0.0, 0.0); bezierVertex(0.0, 0.0, 1.0, 0.4, 1.0, -0.7); endShape(); popMatrix(); } void keyPressed() { if (key == 'c') { x = 30; redraw(); } else if (key == 's') { save("Mod21_14_2.jpg"); } } void mousePressed() { x = 30; nofLeaves=max(2, int (40*mouseX/width)); sizeLeaves =max(5, int (40*mouseY/height)); redraw(); }