Kodewick
Start learning →

Python Turtle Rose

Five layers of petals drawn from the outside in, dark red to pink, each turned a little. Click a number to change the layers, the size or the colors.

Python Turtle Rose
The full code (43 lines)
import turtle

screen = turtle.Screen()
screen.bgcolor("#fff5f5")
t = turtle.Turtle()
t.hideturtle()
t.speed(0)


def petal(x, y, size, angle, color):
    # one petal: a leaf shape between two arcs
    t.penup()
    t.goto(x, y)
    t.setheading(angle)
    t.pendown()
    t.color(color)
    t.begin_fill()
    t.circle(size, 60)
    t.left(120)
    t.circle(size, 60)
    t.end_fill()


# the stem
t.penup()
t.goto(0, 40)
t.pendown()
t.pencolor("forestgreen")
t.pensize(8)
t.goto(0, -230)
t.pensize(1)

# two leaves
petal(0, -120, 90, 20, "seagreen")
petal(0, -160, 90, 130, "seagreen")

# the flower: layer by layer from the outside in, each lighter, smaller and turned a little
colors = ["#8b0a1a", "#b0122a", "#d01c3c", "#e3405a", "#f0657a"]
layers = 5
for k in range(layers):
    size = 110 - k * 18
    for i in range(6):
        petal(0, 40, size, i * 60 + k * 23, colors[k % len(colors)])

How it is drawn

A petal is a leaf shape between two arcs: circle(size, 60) draws a 60 degree arc, a left turn of 120 and another arc bring it back, with begin_fill() and end_fill() around it.

Six petals per layer, 60 degrees apart, go all the way round; outer layers are bigger and darker, each layer in is 18 smaller and lighter.

i * 60 + k * 23: layer k is turned another 23 degrees, so the petals overlap like a real rose.

The leaves come from the same petal function, just green and pointing another way.

Questions

Why are there gaps with other petal counts?

The petals are 60 degrees (360 ÷ 6) apart. Click Edit and change i * 60 to i * 360 / petals to go round evenly.

Can I add a name to it?

Yes: click Edit and add t.penup(), t.goto(0, -260) and t.write("For you", align="center", font=("Arial", 24, "bold")) at the end.

Try another