Python Extras

How to Draw Flower in Python Turtle

We are building a project in which we will learn How to draw a flower with the help of a Python turtle. In this, we will split the code and explain how we can draw a beautiful flower by using functions and methods.

Before moving forward we should have some piece of knowledge about a flower.

A flower is part of the plant it is also known as a blossom. The flower has a pleasant smell and a brightly colored body. Flowers consist of petals and they grow at the top of the stem.

Draw Flower in Python Turtle

Now we are moving forward to start this project. Here we are just importing the below two Python turtle libraries.

from turtle import *
import turtle as tur

Hereafter importing the library now we are creating an object for this turtle.

tur = tur.Turtle()

In python turtle, we are set the initial position of the flower by using the turtle() function. To set the position we have to use the following function.

  • tur.penup() is used to pick up the pen and stop the drawing.
  • tur.left (90) is used to move the turtle in the left direction.
  • tur.fd (200) is used to move the turtle in the forward direction.
  • tur.pendown() is used to start drawing.
  • tur.right (90) is used to move the turtle in the right direction.
tur.penup ()
tur.left (90)
tur.fd (200)
tur.pendown ()
tur.right (90)

Now we are making a flower base by using the turtle() function. To make a beautiful base of a flower we are using the following function.

  • tur.fillcolor (“red”) is used to fill the color inside the base of a flower.
  • tur.begin_fill () is used to start filling the color.
  • tur.circle (10,180) is used to draw the shape of a circle.
  • tur.left (50) is used to move the turtle in the left direction.
  • tur.right (24) is used to move the turtle in the right direction.
  • tur.fd (30) is used to move the turtle in the forward direction.
  • tur.end_fill () is used to stop filling color.
tur.fillcolor ("red")
tur.begin_fill ()
tur.circle (10,180)
tur.circle (25,110)
tur.left (50)
tur.circle (60,45)
tur.circle (20,170)
tur.right (24)
tur.fd (30)
tur.left (10)
tur.circle (30,110)
tur.fd (20)
tur.left (40)
tur.circle (90,70)
tur.circle (30,150)
tur.right (30)
tur.fd (15)
tur.circle (80,90)
tur.left (15)
tur.fd (45)
tur.right (165)
tur.fd (20)
tur.left (155)
tur.circle (150,80)
tur.left (50)
tur.circle (150,90)
tur.end_fill ()

In python turtle, we are using the turtle() function to make the petal 1 of a flower. For making a petal we are using the following function.

  • tur.left (150) is used to move the turtle in the left direction to give the perfect shape to the petal.
  • tur.circle (-90,70) is used to draw the circle.
  • tur.setheading (60) is used to set the orientation of the turtle to angle.
tur.left (150)
tur.circle (-90,70)
tur.left (20)
tur.circle (75,105)
tur.setheading (60)
tur.circle (80,98)
tur.circle (-90,40)

Now we are using the turtle() function to make a petal 2 of a flower. For making a petal we are using the following function.

  • tur.left (180) is used to move the turtle in the left direction.
  • tur.circle (90,40) is used to draw the shape of a circle.
  • tur.setheading (-83) is used to set the orientation of the turtle to angle.
tur.left (180)
tur.circle (90,40)
tur.circle (-80,98)
tur.setheading (-83)

In python turtle, we are using the turtle() function to make a leaf 1 of a flower. For making a leaf we are using the following function.

  • tur.fd (30) is used to move the turtle in the forward direction.
  • tur.left (90) is used to move the turtle in the left direction.
  • tur.fillcolor (“dark green”) is used to fill the color in the shape.
  • tur.begin_fill () is used to start filling the color.
  • tur.circle (-80,90) is used to draw the circle shape.
  • tur.right (90) is used to move the turtle in the right direction.
tur.fd (30)
tur.left (90)
tur.fd (25)
tur.left (45)
tur.fillcolor ("dark green")
tur.begin_fill ()
tur.circle (-80,90)
tur.right (90)
tur.circle (-80,90)
tur.end_fill ()
tur.right (135)
tur.fd (60)
tur.left (180)
tur.fd (85)
tur.left (90)
tur.fd (80)

Now we are using the turtle() function to make a leaf 2 of a flower. For making a leaf we are using the following function.

  • tur.right (90) is used to move the turtle in the right direction.
  • tur.fillcolor (“dark green”) is used to fill the color in the shape.
  • tur.begin_fill () is used to start filling the color.
  • tur.circle (80,90) is used to draw the circle shape.
  • tur.left (90) is used to move the turtle in the left direction.
  • tur.end_fill () is used to end filling the color.

tur.fd (60) is used to move the turtle in the forward direction.

tur.right (90)
tur.right (45)
tur.fillcolor ("dark green")
tur.begin_fill ()
tur.circle (80,90)
tur.left (90)
tur.circle (80,90)
tur.end_fill ()
tur.left (135)
tur.fd (60)
tur.left (180)
tur.fd (60)
tur.right (90)
tur.circle (200,60)
tur.done()

Here after splitting the code and explaining how we can make a flower using python turtle now, we will see how the output looks like after running the whole code.

from turtle import *
import turtle as tur

tur = tur.Turtle()
 

tur.penup ()
tur.left (90)
tur.fd (200)
tur.pendown ()
tur.right (90)
 

tur.fillcolor ("red")
tur.begin_fill ()
tur.circle (10,180)
tur.circle (25,110)
tur.left (50)
tur.circle (60,45)
tur.circle (20,170)
tur.right (24)
tur.fd (30)
tur.left (10)
tur.circle (30,110)
tur.fd (20)
tur.left (40)
tur.circle (90,70)
tur.circle (30,150)
tur.right (30)
tur.fd (15)
tur.circle (80,90)
tur.left (15)
tur.fd (45)
tur.right (165)
tur.fd (20)
tur.left (155)
tur.circle (150,80)
tur.left (50)
tur.circle (150,90)
tur.end_fill ()
 

tur.left (150)
tur.circle (-90,70)
tur.left (20)
tur.circle (75,105)
tur.setheading (60)
tur.circle (80,98)
tur.circle (-90,40)

tur.left (180)
tur.circle (90,40)
tur.circle (-80,98)
tur.setheading (-83)

tur.fd (30)
tur.left (90)
tur.fd (25)
tur.left (45)
tur.fillcolor ("dark green")
tur.begin_fill ()
tur.circle (-80,90)
tur.right (90)
tur.circle (-80,90)
tur.end_fill ()
tur.right (135)
tur.fd (60)
tur.left (180)
tur.fd (85)
tur.left (90)
tur.fd (80)
 
tur.right (90)
tur.right (45)
tur.fillcolor ("dark green")
tur.begin_fill ()
tur.circle (80,90)
tur.left (90)
tur.circle (80,90)
tur.end_fill ()
tur.left (135)
tur.fd (60)
tur.left (180)
tur.fd (60)
tur.right (90)
tur.circle (200,60)
tur.done()

After running the above code we get the following output in which we can see that a beautiful flower is drawn on the screen.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button