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

Colour

Introduction

Everything so far has been white on black, which is what you get if you never say otherwise. The Einstein draws in sixteen colours, and changing them costs one short instruction.

The pen colour

setpc - set pen colour - takes a number from 0 to 15:

setpc 9

Everything drawn after that is in colour 9 until you say otherwise. It does not change what is already on screen, only what comes next.

1 black 5 light blue 9 light red 13 magenta
2 medium green 6 dark red 10 dark yellow 14 grey
3 light green 7 cyan 11 light yellow 15 white
4 dark blue 8 medium red 12 dark green

White is 15, which is why your drawings have been white without your asking.

There is no limit on how many you use at once - all sixteen can be on the screen together.

Give it a number outside the range and it says so rather than guessing:

?setpc 20
setpc doesn't like 20 as input

That form of complaint - this primitive doesn't like that as input - is one you will meet again whenever you hand something the wrong sort of value.

The background

setbg takes the same numbers and fills the whole drawing screen:

setbg 4

Dark blue, in that case. Worth knowing that a colour drawn on top of the same background colour is invisible, which is occasionally useful and more often the explanation for a drawing that has gone missing.

The code

Starting from

A fresh boot, at the ? prompt.

What you should see

Three squares sharing their bottom left corner - a green one forty steps on a side, a light red one sixty, and a light yellow one eighty. Where a bigger square runs along the same edge as a smaller one, the colour you see is the one drawn last.

Three nested squares in green, red and yellow

ht is there to keep the turtle out of the picture; without it, it sits on the corner where all three squares meet.

Change one thing

  • Change the first setpc 2 to setpc 1. The green square goes. Where has it gone, and what would you have to change to see it again?
  • Put setbg 4 on a line of its own after cs, and run the whole thing again. Which of the three squares is hardest to see now, and why that one?
  • Change the last setpc 11 to setpc 16. What does Dr Logo say, and at what point does it say it - before or after drawing the first two squares?

When it goes wrong

Symptom Cause
setpc doesn't like 20 as input The colour numbers stop at 15.
A shape you know you drew is not there It is probably the same colour as the background. Black is 1 and the background starts black.
Part of one shape changed colour Two shapes are sharing an edge. Whichever was drawn last is the one you can see.
The colour changes but nothing already drawn does That is how it works - setpc affects what comes next, not what is there.

Summary

setpc sets the drawing colour and setbg the background, both taking a number from 0 to 15. A colour applies to everything drawn after it. Out-of-range numbers are refused rather than guessed at.

Next

S8, running off the edge - what happens when the turtle walks out of the screen, and the three different things you can ask it to do about that.

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.