/********************************************************** Variable Declarations Each variable is given an initial value ***********************************************************/ // Variables for the window dimensions int windowWidth = 300; // Note: the fraction below uses integers because the dimension // of the display window is in units of pixels, i.e. integer type int windowHeight = windowWidth * 3/2; // 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)(windowWidth * 0.5); int flowerCenterY = (int)(windowHeight * 0.3); int circleSize = 30; // Distance from the center of the flower to the petals int dist = 50; // The first petal is vertically aligned to the center of the flower // 90 degree in radians float startingAngle = -PI/2.0; // Number of petals used int numberOfPetals = 5; // Angle separating each petal around the center (2*PI = 360 degrees) float angleIncrement = 2 * PI/numberOfPetals; // Petal up which is aligned to the center of the flower float petal1X = flowerCenterX; float petal1Y = flowerCenterY - dist; // Could equivalently be computed as follow // (adhering to the formula used below) //float petal1X = flowerCenterX + dist * cos(startingAngle); //float petal1Y = flowerCenterY + dist * sin(startingAngle); // Next petal, beside petal1, clockwise (right side E) // (sin and cos function needs the angle parameter in radians) float nextAngle = startingAngle + angleIncrement; float petal2RX = flowerCenterX + dist * cos(nextAngle); float petal2RY = flowerCenterY + dist * sin(nextAngle); // Next petal, beside petal2R, clockwise (right side SE) nextAngle = startingAngle + 2 * angleIncrement; float petal3RX = flowerCenterX + dist * cos(nextAngle); float petal3RY = flowerCenterY + dist * sin(nextAngle); // Next petal, beside petal1, counter-clockwise (left side W) // Done this way because sin and cos function angle in radians // needs to be between 0 to PI*2 nextAngle = startingAngle - angleIncrement; float petal2LX = flowerCenterX + dist * cos(nextAngle); float petal2LY = flowerCenterY + dist * sin(nextAngle); // Next petal, beside petal2L, counter-clockwise (left side SW) nextAngle = startingAngle - 2 * angleIncrement; float petal3LX = flowerCenterX + dist * cos(nextAngle); float petal3LY = flowerCenterY + dist * sin(nextAngle); /********************************************************** Code ***********************************************************/ // Setting the window and painting attributes // The size() function must be the first line of code size(windowWidth, windowHeight); // The background() function sets the color used for // the background of the Processing window. // The color is white background(255, 255, 255); // Disables drawing the stroke (outline) noStroke(); // The fill() function sets the color used to fill shapes // The color is pink fill(245, 190, 190); // Draw an ellipse at the flower center location of dimensions // circleSize for the width and height of the shape ellipse(flowerCenterX, flowerCenterY, circleSize, circleSize); // 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 * circleSize, 1.4 * circleSize); // Draw petals on the right side ellipse(petal2RX, petal2RY, 1.4 * circleSize, 1.4 * circleSize); ellipse(petal3RX, petal3RY, 1.4 * circleSize, 1.4 * circleSize); // Draw petals on the left side ellipse(petal2LX, petal2LY, 1.4 * circleSize, 1.4 * circleSize); ellipse(petal3LX, petal3LY, 1.4 * circleSize, 1.4 * circleSize); // for debugging //stroke(0, 0, 0); //strokeWeight(10); //point(flowerCenterX, flowerCenterY); //println(flowerCenterX + " " + flowerCenterY); //println(startingAngle + " " + angleIncrement);