Functions to Draw Flowers
If we want to use processing functions to draw complex objects like flowers, we'll want to get more comfortable using the processing transform functions: pushMatrix(), popMatrix(), translate( ), scale( ), and rotate( ).
Processing has functions to draw complex shapes:
Here's a link to a tool that will allow designing such shapes within the khan academy:
When using the bezierVertex tool, it may be best to position your shape in the upper left corner so that the shape is defined in relation to the origin, the code below for the flower petals works best when the bezier shape is defined at the canvas origin point.
If we use the end points and control points to drag our shape to the origin, it'll be easier to use for creating our flower.
Thinking about drawing a flower
If we were to draw a flowering plant on paper, would we start with plant base or the flower petals? There's no correct approach, either way can work.
This is also true with programming, but we'll want to create a flexible program so we can draw all shapes and locations of the flower on the canvas.
Draw A Plant - Start with lines for a stem.
For code to draw a stem, we can use a line, we will want to reposition flowers, so the 2 line points must be function input parameters.
The function below draws 3 lines, with the middle line to hold the flower.
Draw a Flower - start with more stem lines
We can begin by drawing more stem lines - from the stem connection point to the flower's center point, then we'll translate the origin to the flower's center point.
Draw Petal Logic
The code below takes a section of a bezierVertex shape and puts it inside a function so we can determine where we want to draw petals. If we add angle and scaleX, scaleY as input parameters to our function, then we can flip the flower petal.
Put all of the pieces together
Last updated