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.

The turtle draws when its pen is down. Use penup() to lift the pen and pendown() to put it back down. The turtle can move while the pen is up without drawing a line.

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

Two black 50-unit horizontal lines, separated by a 50-unit gap where the turtle moved with its pen up.

You can change the line color with color(). You can use common color names like "red", "blue" or "green". Colors always have to be between quotes ("). You can also change the line width with pensize().

otto.color("blue")
otto.pensize(4)
otto.forward(80)

A blue 80-unit horizontal line starts at the canvas center, drawn with a line width of 4.

You can change the color as often as you like. Every line is drawn in the color that was set when the turtle drew it:

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

A red 100-unit line and a blue 100-unit line, separated by a 50-unit gap.

Summary

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