Python and Turtle Difficulty Level 2,python,Tutorial Tutorial: Drawing a Flower Petal or a Leaf with Python Turtle

Tutorial: Drawing a Flower Petal or a Leaf with Python Turtle

In this tutorial we are going to show how to draw a flower’s petal (or a leaf). This is a simple two step process: 1. draw an arc of a circle 2. turn around and draw the other arc.

Step 1: Drawing the first arc. Obviously, we are not drawing a full circle. You can use the extent value to decide how many degree arc to draw. Usually, a number between 60 to 120 will create a good looking petal. The bigger the angle, the wider the petal will become. In this example, we are going to use 70 degrees. The following is the code snippet for the first arc:

turtle.up()
turtle.goto(-100,-100)
turtle.down()
turtle.circle(300,70)
First Arc of a Petal

Step 2: Drawing the second arc. We need to draw the second arc in the opposite direction to the first arc so that it can go back to the original position. Since the heading of the turtle changed by the degree of the first arc, you just need to turn 180 minus the degree of the first arc. Since, we used 70 degrees in the example above, we will turn left 110 (180-70) degrees. The following is the code snippet to draw the second arc:

turtle.left(110)
turtle.circle(300,70)

Now we just to color it with your favorite color. The following is the complete code for drawing the flower petal:

turtle.up()
turtle.goto(-100,-100)
turtle.down()
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.circle(300,70)
turtle.left(110)
turtle.circle(300,70)
turtle.end_fill()

Challenge: Draw a five petal flower.

Tags:

Related Post