Editor

Python Turtle Flower

Beginner · Nature · 56 lines · draws in about 15 seconds

Every petal and leaf comes from one function that draws two arcs meeting at both ends, turned to point a different way each time.

Python Turtle Flower: the finished drawing
import turtle
screen = turtle.Screen()
screen.bgcolor("aliceblue")
screen.title("Flower")
t = turtle.Turtle()
t.speed(6)
def draw_petal(size, outline, fill):
# Two arcs that meet at both ends make a pointed petal
t.color(outline, fill)
t.begin_fill()
t.right(35) # half of 70, so the petal points straight ahead
t.circle(size, 70)
t.left(110) # 180 - 70: turn round at the tip
t.circle(size, 70)
t.left(145) # 110 + 35: face the way the turtle started
t.end_fill()
# The stem: a thick green line
t.penup()
t.goto(0, -220)
t.setheading(90)
t.pendown()
t.pensize(10)
t.color("forestgreen")
t.forward(290)
# Two leaves, made with the same petal shape
t.pensize(2)
t.penup()
t.goto(0, -150)
t.pendown()
t.setheading(135)
draw_petal(80, "darkgreen", "limegreen")
t.setheading(45)
draw_petal(80, "darkgreen", "limegreen")
# Twelve petals around the middle, the first one pointing straight up
t.penup()
t.goto(0, 70)
t.pendown()
t.setheading(90)
for i in range(12):
draw_petal(120, "mediumvioletred", "hotpink")
t.left(30)
# The centre
t.dot(64, "darkorange")
t.dot(40, "gold")
t.hideturtle()
turtle.done()

How the code works

A petal from two arcs

circle(size, 70) draws 70 degrees of a circle. Turning left(110) at the tip and drawing the same arc again brings the turtle back to where it started, and the two arcs enclose a pointed petal. The right(35) before and the extra 35 degrees after keep the petal pointing the way the turtle faced.

def draw_petal(size, outline, fill):
    # Two arcs that meet at both ends make a pointed petal
    t.color(outline, fill)
    t.begin_fill()
    t.right(35)          # half of 70, so the petal points straight ahead
    t.circle(size, 70)
    t.left(110)          # 180 - 70: turn round at the tip
    t.circle(size, 70)
    t.left(145)          # 110 + 35: face the way the turtle started
    t.end_fill()

A thick stem

setheading(90) points the turtle straight up. With pensize(10), one forward(290) draws the stem from near the bottom of the screen to the middle of the flower.

# The stem: a thick green line
t.penup()
t.goto(0, -220)
t.setheading(90)
t.pendown()
t.pensize(10)
t.color("forestgreen")
t.forward(290)

Leaves use the petal function

A leaf is a smaller petal in green. Pointing the turtle at 135 degrees and then at 45 degrees puts one leaf on each side of the stem.

# Two leaves, made with the same petal shape
t.pensize(2)
t.penup()
t.goto(0, -150)
t.pendown()
t.setheading(135)
draw_petal(80, "darkgreen", "limegreen")
t.setheading(45)
draw_petal(80, "darkgreen", "limegreen")

Twelve petals and a centre

After each petal the turtle turns left(30), and twelve turns of 30 degrees make a full circle. Two dot() calls, a big orange one and a smaller gold one on top, cover the inner ends of the petals.

# Twelve petals around the middle, the first one pointing straight up
t.penup()
t.goto(0, 70)
t.pendown()
t.setheading(90)
for i in range(12):
    draw_petal(120, "mediumvioletred", "hotpink")
    t.left(30)

# The centre
t.dot(64, "darkorange")
t.dot(40, "gold")

Make it yours

Change the code above and press Run. Some ideas:

  • Change range(12) to range(8) and t.left(30) to t.left(45) for a flower with eight petals.
  • Change "hotpink" to "gold" and "mediumvioletred" to "darkorange" for a yellow flower.
  • Change draw_petal(120, "mediumvioletred", "hotpink") to draw_petal(90, "mediumvioletred", "hotpink") for a smaller flower head.

What it uses

Every turtle command the site supports is listed on Python turtle online.