Editor

Draw a Robot in Python Turtle

Beginner · Things to draw · 104 lines · draws in about 7 seconds

Two helper functions, one for rectangles and one for circles, build the whole robot, and drawing the arms first lets the body cover the shoulders.

Draw a Robot in Python Turtle: the finished drawing
import turtle
screen = turtle.Screen()
screen.bgcolor("lavender")
screen.title("Robot")
t = turtle.Turtle()
t.speed(8)
def rectangle(x, y, width, height, color):
# A filled rectangle with its bottom left corner at (x, y)
t.penup()
t.goto(x, y)
t.setheading(0)
t.pendown()
t.pensize(1)
t.color(color)
t.begin_fill()
for _ in range(2):
t.forward(width)
t.left(90)
t.forward(height)
t.left(90)
t.end_fill()
def circle_at(x, y, size, color):
# A filled circle (a dot) centred on (x, y)
t.penup()
t.goto(x, y)
t.dot(size, color)
def arm(x, y, heading):
# An arm is a very thick line from the shoulder, with a round hand
t.penup()
t.goto(x, y)
t.setheading(heading)
t.pendown()
t.pensize(26)
t.pencolor("slategray")
t.forward(95)
t.dot(46, "dimgray")
# Arms first, so the body covers the shoulders.
# The left arm hangs down, the right arm waves.
arm(-90, 20, 235)
arm(90, 20, 50)
# Feet, legs and body
rectangle(-95, -215, 80, 22, "darkslategray")
rectangle(15, -215, 80, 22, "darkslategray")
rectangle(-75, -193, 40, 65, "slategray")
rectangle(35, -193, 40, 65, "slategray")
rectangle(-100, -130, 200, 165, "steelblue")
# A screen with a heartbeat line, and three buttons on the chest
rectangle(-60, -55, 120, 60, "midnightblue")
t.penup()
t.goto(-50, -25)
t.pendown()
t.pensize(3)
t.pencolor("lime")
for point in [(-20, -25), (-10, -5), (2, -45), (12, -25), (50, -25)]:
t.goto(point)
circle_at(-30, -90, 22, "red")
circle_at(0, -90, 22, "gold")
circle_at(30, -90, 22, "lime")
# Neck, head and two round ears
rectangle(-20, 35, 40, 20, "slategray")
circle_at(-88, 110, 30, "darkorange")
circle_at(88, 110, 30, "darkorange")
rectangle(-85, 55, 170, 110, "lightsteelblue")
# Antenna with a red light on top
t.penup()
t.goto(0, 165)
t.setheading(90)
t.pendown()
t.pensize(6)
t.pencolor("slategray")
t.forward(35)
t.dot(26, "red")
# Eyes: white, blue, and a little white sparkle
for x in [-40, 40]:
circle_at(x, 125, 48, "white")
circle_at(x, 125, 24, "dodgerblue")
circle_at(x + 6, 131, 8, "white")
# A smile: part of a circle, from left to right
t.penup()
t.goto(-35, 85)
t.setheading(-50)
t.pendown()
t.pensize(6)
t.pencolor("darkslategray")
t.circle(45, 100)
t.hideturtle()
turtle.done()

How the code works

A rectangle helper

rectangle() draws a filled box from its bottom left corner. The feet, legs, body, chest screen, neck and head are all calls to it.

def rectangle(x, y, width, height, color):
    # A filled rectangle with its bottom left corner at (x, y)
    t.penup()
    t.goto(x, y)
    t.setheading(0)
    t.pendown()
    t.pensize(1)
    t.color(color)
    t.begin_fill()
    for _ in range(2):
        t.forward(width)
        t.left(90)
        t.forward(height)
        t.left(90)
    t.end_fill()

Arms

An arm is one line with pensize(26), which gives it round ends, and a dot for the hand. A heading of 235 points down and to the left, and 50 points up and to the right for the wave.

def arm(x, y, heading):
    # An arm is a very thick line from the shoulder, with a round hand
    t.penup()
    t.goto(x, y)
    t.setheading(heading)
    t.pendown()
    t.pensize(26)
    t.pencolor("slategray")
    t.forward(95)
    t.dot(46, "dimgray")

Built from the bottom up

Each rectangle is placed by its bottom left corner, so each part starts where the one below it ends: the feet are 22 tall, so the legs start at -193.

# Feet, legs and body
rectangle(-95, -215, 80, 22, "darkslategray")
rectangle(15, -215, 80, 22, "darkslategray")
rectangle(-75, -193, 40, 65, "slategray")
rectangle(35, -193, 40, 65, "slategray")
rectangle(-100, -130, 200, 165, "steelblue")

The face

Three dots of shrinking size make each eye, with the sparkle a little up and to the right. The smile is 100 degrees of a circle, started pointing down and to the right with setheading(-50).

# Eyes: white, blue, and a little white sparkle
for x in [-40, 40]:
    circle_at(x, 125, 48, "white")
    circle_at(x, 125, 24, "dodgerblue")
    circle_at(x + 6, 131, 8, "white")

# A smile: part of a circle, from left to right
t.penup()
t.goto(-35, 85)
t.setheading(-50)
t.pendown()
t.pensize(6)
t.pencolor("darkslategray")
t.circle(45, 100)

Make it yours

Change the code above and press Run. Some ideas:

  • Make the robot wave with both arms: change arm(-90, 20, 235) to arm(-90, 20, 130).
  • Change "steelblue" to "mediumseagreen" for a green body.
  • Change the antenna light t.dot(26, "red") to t.dot(26, "lime") so it shines green.

What it uses

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