Editor

Python Turtle Mandala

Intermediate · Patterns and spirals · 58 lines · draws in about 17 seconds

The mandala is built in layers around one centre, a lace of thin circles first, then three rings of twelve petals and a ring of gold dots on top.

Python Turtle Mandala: the finished drawing
import turtle
screen = turtle.Screen()
screen.bgcolor("#1b1035")
screen.title("Mandala")
t = turtle.Turtle()
t.speed(10)
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(30) # half of 60, so the petal points straight ahead
t.circle(size, 60)
t.left(120) # 180 - 60: turn round at the tip
t.circle(size, 60)
t.left(150) # 120 + 30: face the way the turtle started
t.end_fill()
def draw_ring(count, size, outline, fill, start_angle):
# A ring of petals around the centre, evenly spaced
t.setheading(start_angle)
for i in range(count):
draw_petal(size, outline, fill)
t.left(360 / count)
# Lace in the background: 36 thin circles turned around the centre
t.pensize(1)
t.pencolor("turquoise")
for i in range(36):
t.circle(95)
t.left(10)
# Three rings of petals, from the biggest to the smallest
t.pensize(2)
draw_ring(12, 175, "plum", "#7b2cbf", 15)
draw_ring(12, 135, "pink", "#c9184a", 0)
draw_ring(12, 90, "gold", "darkorange", 15)
# A circle of gold dots around the outside
t.penup()
for i in range(24):
t.setheading(i * 15)
t.forward(205)
t.dot(10, "gold")
t.backward(205)
# The centre
t.dot(56, "gold")
t.dot(34, "#c9184a")
t.dot(12, "white")
t.hideturtle()
turtle.done()

How the code works

One petal

Two 60 degree arcs that meet at both ends make a pointed petal. The right(30) before and the extra 30 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(30)          # half of 60, so the petal points straight ahead
    t.circle(size, 60)
    t.left(120)          # 180 - 60: turn round at the tip
    t.circle(size, 60)
    t.left(150)          # 120 + 30: face the way the turtle started
    t.end_fill()

A ring of petals

draw_ring() calls draw_petal() count times and turns 360 / count degrees after each one, so the petals are evenly spaced. start_angle sets which way the first petal points.

def draw_ring(count, size, outline, fill, start_angle):
    # A ring of petals around the centre, evenly spaced
    t.setheading(start_angle)
    for i in range(count):
        draw_petal(size, outline, fill)
        t.left(360 / count)

Lace first, then petals

36 thin turquoise circles go down first, as the background. Then come three rings of petals, biggest first so each smaller ring sits on top; the middle ring starts at 0 degrees and the others at 15, so its petals show in the gaps.

# Lace in the background: 36 thin circles turned around the centre
t.pensize(1)
t.pencolor("turquoise")
for i in range(36):
    t.circle(95)
    t.left(10)

# Three rings of petals, from the biggest to the smallest
t.pensize(2)
draw_ring(12, 175, "plum", "#7b2cbf", 15)
draw_ring(12, 135, "pink", "#c9184a", 0)
draw_ring(12, 90, "gold", "darkorange", 15)

Dots round the edge and in the middle

For each gold dot the turtle faces a new direction, moves out 205 steps with the pen up, drops a dot() and comes back. Three dots of shrinking size, one on top of another, make the centre.

# A circle of gold dots around the outside
t.penup()
for i in range(24):
    t.setheading(i * 15)
    t.forward(205)
    t.dot(10, "gold")
    t.backward(205)

# The centre
t.dot(56, "gold")
t.dot(34, "#c9184a")
t.dot(12, "white")

Make it yours

Change the code above and press Run. Some ideas:

  • Change draw_ring(12, 175, "plum", "#7b2cbf", 15) to draw_ring(24, 175, "plum", "#7b2cbf", 15) for a fuller outer ring.
  • Change t.pencolor("turquoise") to t.pencolor("gold") for golden lace behind the petals.
  • Change t.circle(95) to t.circle(95, steps=5) so the lace is made of pentagons.

What it uses

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