• fullscreen
• flower_maker_v1.pde
• ```/**
* Flower Maker
* Version 1.0
* by Ray Elder
*
* 17 May 2010
*
* Function to draw multiple flowers using translate().
*/

Boolean verbose = true;       // set verbose to false to remove points and control points
int radius = 10;              // sets the center radius of the flower
int totalPetals = 8;
float petalLength = 100;

void setup() {
size(450, 450);
background(255);
smooth();
noLoop();
}

void draw() {
translate(125, 225);
drawFlower();
translate(200, 0);
drawFlower();
}

void drawFlower() {
int centerX = 0;
int centerY = 0;
int diameter = radius * 2;
if (verbose) {
// if true draw center point
noStroke();
fill(255, 0, 0);
ellipse(centerX, centerY, 5, 5);
}
noFill();
stroke(0);
// draw center ellipse of the flower
ellipse (centerX, centerY, diameter, diameter);

// calculate rotation angle based on the number of petals and set to radians
float angle = radians(360 / totalPetals);
for (int i = 0; i < totalPetals; i++) {

// call drawPetal function to calculate control points and set bezierVertices

// increment angle based on total number of petals
rotate(angle);
}

}

void drawPetal(int startX, int startY) {

// set offset for control points
float bezierDiff = petalLength / 3;

// calculate start's top control point
float startAngleTopX = startX + bezierDiff;
float startAngleTopY = startY + bezierDiff;

// calculate start's bottom control point
float startAngleBottomX = startX - bezierDiff;
float startAngleBottomY = startY + bezierDiff;

// calculate end point
float endX = startX;
float endY = startY + petalLength;

// calculate end's top control point
float endAngleTopX = endX + bezierDiff;
float endAngleTopY = endY - bezierDiff;

// calculate end's bottom control point
float endAngleBottomX = endX - bezierDiff;
float endAngleBottomY = endY - bezierDiff;

if (verbose) {
// if true draw point and control points
noStroke();
fill(255,0,0);
ellipse(startX, startY, 5, 5);
ellipse(startAngleTopX, startAngleTopY, 5, 5);
ellipse(startAngleBottomX, startAngleBottomY, 5, 5);
ellipse(endAngleTopX, endAngleTopY, 5, 5);
ellipse(endAngleBottomX, endAngleBottomY, 5, 5);
ellipse(endX, endY, 5, 5);
noFill();
stroke(0);
}

// draw petal shape with points and control points
beginShape();
vertex(startX, startY);
bezierVertex(startAngleTopX, startAngleTopY, endAngleTopX, endAngleTopY, endX, endY);
bezierVertex(endAngleBottomX, endAngleBottomY, startAngleBottomX, startAngleBottomY, startX, startY);
endShape();
}

// create PNG image of complete flower
void keyPressed() {
if (key =='c' || key == 'C') {
save ("flower_maker_v1.png");
}
}

```

tweaks (0)

This sketch is running as Java applet, exported from Processing.