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.

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)toarm(-90, 20, 130). - Change
"steelblue"to"mediumseagreen"for a green body. - Change the antenna light
t.dot(26, "red")tot.dot(26, "lime")so it shines green.
What it uses
- functions with parameters
- begin_fill and end_fill
- dot
- drawing order
Every turtle command the site supports is listed on Python turtle online.