Dr Logo for the Tatung Einstein, showing a rosette drawn by the turtle
← Back to Courses
module
6

Lifting the pen

Introduction

Everything the turtle has drawn so far has been joined up, because the pen has been down the whole time. A drawing with two separate things in it needs a way to move without leaving a trail.

Up and down

Two instructions, and neither takes a number:

Type Short for What it does
pu pen up The turtle still moves, but draws nothing
pd pen down Back to drawing

The turtle keeps moving and turning exactly as before. The only thing that changes is whether a line appears behind it.

That is worth saying plainly, because it is easy to think of pu as "stop" - it is not. pu followed by fd 40 puts the turtle forty steps further on, and the next thing you draw will start from there.

A line with gaps in it

Put pu and pd inside a repeat and you get a dashed line: draw a bit, skip a bit, over and over.

repeat 5 [pd fd 15 pu fd 10]

Each time round: pen down, draw fifteen steps, pen up, skip ten. The pd at the start of the list matters - without it, the second time round would begin with the pen still up from the end of the first.

The code

Starting from

A fresh boot, at the ? prompt. The rt 90 turns the turtle to face right before it sets off, so the dashes run across the screen rather than up it - there is more room that way.

What you should see

Five dashes running to the right from the middle of the screen, each one about fifteen steps long with a ten-step gap after it, and the turtle at the far right end pointing right.

A dashed line drawn with the pen going up and down

Change one thing

  • Swap the pd and the pu round, so the list reads pu fd 15 pd fd 10. You still get dashes. What is different about them, and where does the line now start?
  • Change pu fd 10 to pu fd 30, leaving everything else. Count the dashes before you run it, then count them afterwards. Why are there fewer?
  • Take the pu out altogether, leaving repeat 5 [pd fd 15 fd 10]. What do you get, and what does that tell you about what fd 15 fd 10 does on its own?

When it goes wrong

Symptom Cause
Nothing is drawn at all The pen is up from something you did earlier. pd puts it back down; cs also resets it.
The first dash is missing but the rest are there The pen was up when the repeat started. That is what the pd at the front of the list is for.
The dashes stop before the edge of the screen You have run out of room. Five dashes of 15 with 10-step gaps is 125 steps, and there are about 128 to the right of the middle.
You get one long line instead of dashes The pu is missing, or there is no space between it and the instruction after it.

Summary

pu lifts the pen and pd puts it down. The turtle moves the same either way - only the line changes. Putting both inside a repeat is how you draw something with gaps in it.

Next

S7, colour - the pen does not have to be white.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.