/* * Demonstration of a flower() function. * Uses transformations to make elliptical petals. */ void setup() { size(600, 600); pushMatrix(); translate(0.25*width, 0.25*height); flower(13, 0.25*width, 0.0625*width, color(255, 125, 125), color(255, 255, 0)); popMatrix(); pushMatrix(); translate(0.75*width, 0.25*height); advancedFlower(13, 0.25*width, 0.0625*width, color(255, 125, 125), color(255, 255, 0)); popMatrix(); pushMatrix(); translate(0.25*width, 0.75*height); flower(13, 0.25*width, 0.125*width, color(255, 255, 255), color(255, 255, 0)); popMatrix(); pushMatrix(); translate(0.75*width, 0.75*height); advancedFlower(13, 0.25*width, 0.125*width, color(255, 255, 255), color(255, 255, 0)); popMatrix(); } void draw() { } // Draws flower center around origin void flower(int numPetals, float petalLength, float petalWidth, color petalColor, color centerColor) { float theta = TWO_PI/numPetals; fill(petalColor); for (int j=0; j < numPetals; j++) { pushMatrix(); rotate(j*theta); ellipse(0.5*petalLength, 0, petalLength, petalWidth); popMatrix(); } fill(centerColor); ellipse(0, 0, 0.5*petalLength, 0.5*petalLength); } // Draws flower center around origin // In this version, we place every other petal first // to get more symmetric layering void advancedFlower(int numPetals, float petalLength, float petalWidth, color petalColor, color centerColor) { float theta = TWO_PI/numPetals; fill(petalColor); for (int start=0; start <= 1; start++) { // count by two... for (int j=start; j < numPetals; j += 2) { pushMatrix(); rotate(j*theta); ellipse(0.5*petalLength, 0, petalLength, petalWidth); popMatrix(); } } fill(centerColor); ellipse(0, 0, 0.5*petalLength, 0.5*petalLength); }