A rose with functions
Section 13: Pro drawing and chartsLesson 13.1 · ⏱ 10 min
🎯 Project goal
A rose of 12 coloured petals. We draw one petal in a function, then repeat it as we turn.

t.circle(60, 60) draws an arc (part of a circle with radius 60, at an angle of 60). Two arcs facing each other make a petal. colors[i % 6] starts the colours again after the sixth colour.
import turtle
t = turtle.Turtle()
t.speed(0)
colors = ["red", "orange", "gold", "green", "blue", "purple"]
def petal():
t.circle(60, 60)
t.left(120)
t.circle(60, 60)
t.left(120)
for i in range(12):
t.color(colors[i % 6])
petal()
t.right(30)
t.hideturtle()
🐍 Open the code in Robo Python ↗- Make it 18 petals and a 20-degree turn.
- Change the radius to 100 and notice the rose's shape.
📌 Another example: a flower with six petals
A petal function draws a petal, and we repeat it 6 times.
import turtle
t = turtle.Turtle()
t.speed(0)
t.color("deeppink")
def petal():
t.circle(60, 60)
t.left(120)
t.circle(60, 60)
t.left(120)
for i in range(6):
petal()
t.left(60)
🐍 Open the code in Robo Python ↗
✍️ Practise
Try the lesson's examples here: copy the code, change it, and click ▶ Run.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
A flower with eight petals (a 45 turn).
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
t.speed(0)
t.color("orange")
def petal():
t.circle(60, 60)
t.left(120)
t.circle(60, 60)
t.left(120)
for i in range(8):
petal()
t.left(45)
🐍 Open the code in Robo Python ↗
Result: eight petals.
Medium
A flower with a green stem under it.
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
t.speed(0)
t.color("red")
def petal():
t.circle(50, 60)
t.left(120)
t.circle(50, 60)
t.left(120)
for i in range(6):
petal()
t.left(60)
t.color("green")
t.pensize(4)
t.right(90)
t.forward(150)
🐍 Open the code in Robo Python ↗
Result: a flower with a stem.
Hard
Three flowers in different colours (a flower(x, color) function).
👀 Show the solution🙈 Hide the solution
import turtle
t = turtle.Turtle()
t.speed(0)
def petal(size):
t.circle(size, 60)
t.left(120)
t.circle(size, 60)
t.left(120)
def flower(x, color):
t.penup()
t.goto(x, 0)
t.pendown()
t.color(color)
for i in range(6):
petal(40)
t.left(60)
flower(-140, "red")
flower(0, "gold")
flower(140, "purple")
🐍 Open the code in Robo Python ↗
Result: three flowers.

