Learning goals

  • Lift and lower the turtle’s pen to control when it draws.
  • Change the line color and width.
  • Explain how pen settings affect the lines the turtle draws.

How do you move without drawing?

The turtle’s pen is down by default, so it draws as it moves. Use penup() to lift the pen. Use pendown() to lower it again.

import turtle as otto

otto.penup()
otto.backward(75)
otto.pendown()
otto.forward(50)
otto.penup()
otto.forward(50)
otto.pendown()
otto.forward(50)

Animation of Turtle drawing two black lines with a gap between them.

The turtle starts in the middle and faces right. With its pen up, backward(75) moves it 75 units left without drawing. The turtle draws two lines of 50 units, with a 50 unit gap between them.

How do you change line color and width?

Use color() to set the line color. Put a color name, such as "blue", inside quotes. Use pensize() to set the line width.

import turtle as otto

otto.penup()
otto.backward(40)
otto.pendown()
otto.color("blue")
otto.pensize(4)
otto.forward(80)

Animation of Turtle drawing a blue line, 80 units long and 4 units wide.

The line is blue and 4 units wide. You can choose other color names and line widths.

Try it yourself: Click the Run button. The drawing appears below the code.

Then choose another color and a thicker line. Click Run again. You can find more color names at the bottom of this page.

import turtle as otto

otto.penup()
otto.backward(40)
otto.pendown()
otto.color("blue")
otto.pensize(4)
otto.forward(80)

How can you change color between lines?

You can change the color whenever you like. Each line keeps the color set when Turtle drew it.

import turtle as otto

otto.penup()
otto.backward(105)
otto.pendown()
otto.color("red")
otto.forward(100)
otto.penup()
otto.forward(50)
otto.pendown()
otto.color("blue")
otto.forward(100)

Animation of Turtle drawing a red line and a blue line, with a gap between them.

The turtle draws a red line, moves without drawing, then draws a blue line.

Summary

Command What it does
otto.penup() Lifts the pen so movement does not draw.
otto.pendown() Lowers the pen so movement draws again.
otto.color(color) Sets the line color, for example "red".
otto.pensize(width) Sets the line width.

The labels show color names that otto.color() can use. Put the name in quotation marks, like otto.color("red").

Turtle basic colors