size(300, 450); background(255, 255, 255); noStroke(); // Variables for the flower drawing // The result on the right-hand side of the assignment is converted // to integer as the coordinates of the center of the flower is defined as // of type integer int flowerCenterX = (int)(width * 0.5); int flowerCenterY = (int)(height * 0.3); int pistilSize = 30; // The color of the pistil is pink fill(245, 190, 190); ellipse(flowerCenterX, flowerCenterY, pistilSize, pistilSize); // Distance from the pistil to the petals int dist = 50; // The first petal is vertically aligned to the center of the flower // 90 degree in radians float startingAngle = 0; // Number of petals used int numberOfPetals = 5; // Angle separating each petal around the center; (2*PI = 360 degrees) // CCW: negative in Processing float angleIncrement = -2 * PI/numberOfPetals; float petal1X = flowerCenterX + dist * cos(startingAngle); float petal1Y = flowerCenterY + dist * sin(startingAngle); // Next petal, beside petal1, counterclockwise float nextAngle = startingAngle + angleIncrement; float petal2X = flowerCenterX + dist * cos(nextAngle); float petal2Y = flowerCenterY + dist * sin(nextAngle); // Next petal, beside petal2R nextAngle = startingAngle + 2 * angleIncrement; float petal3X = flowerCenterX + dist * cos(nextAngle); float petal3Y = flowerCenterY + dist * sin(nextAngle); nextAngle = startingAngle + 3 * angleIncrement; float petal4X = flowerCenterX + dist * cos(nextAngle); float petal4Y = flowerCenterY + dist * sin(nextAngle); // Next petal... nextAngle = startingAngle + 4 * angleIncrement; float petal5X = flowerCenterX + dist * cos(nextAngle); float petal5Y = flowerCenterY + dist * sin(nextAngle); // The fill colour is changed to yellow fill(250, 250, 140); // Draw an ellipse at the petal1 location. // What is the width and height of that ellipse? ellipse(petal1X, petal1Y, 1.4 * pistilSize, 1.4 * pistilSize); // Draw petals ellipse(petal2X, petal2Y, 1.4 * pistilSize, 1.4 * pistilSize); ellipse(petal3X, petal3Y, 1.4 * pistilSize, 1.4 * pistilSize); // Draw petals on the left side ellipse(petal4X, petal4Y, 1.4 * pistilSize, 1.4 * pistilSize); ellipse(petal5X, petal5Y, 1.4 * pistilSize, 1.4 * pistilSize); // for debugging //stroke(0, 0, 0); //strokeWeight(10); //point(flowerCenterX, flowerCenterY); //println(flowerCenterX + " " + flowerCenterY); //println(startingAngle + " " + angleIncrement);