Beginners Series Part 11

Bring your micro to life with a touch of colour. We show you how simply it can be done.

Volume 2

Number 1

March 1984

Let's dip into the Micro's colouring box

AS promised last month, we'll be covering colours this time, and seeing how easy they are to use.

In fact, before I give you the theory, try running Program I, and see what happens:

10 REM *** PROGRAM I ***
20 MODE 5
40 PRINT'' "Colour 1"
60 PRINT'' "Colour 2"
80 PRINT'' "Colour 3"

It writes in three different colours! The way you get the micro to change the colour of its writing (we should really say text) is to use the COLOUR command.

COLOUR 1 causes it to print text in colour 1 from then on. In Mode 5 colour 1 is red.

COLOUR 2 causes text to be printed in colour 2. As you can see, in Mode 5 this is yellow.

COLOUR 3 obviously gives white.

So, in Mode 5 COLOUR 1 gives red text, COLOUR 2 gives yellow text, and COLOUR 3 gives white text. Actually, you can fiddle with this, but more of that later.

When you think about it, there are four colours on the screen - the red, yellow and white writing in the foreground plus a black background.

You can actually choose to write in black if you want to by using COLOUR 0, but you won't notice it against the black background. If you don't believe me try adding these lines to Program I:

100 PRINT '' "Colour 0"

Now Mode 5 is a four colour mode, as is Mode 1. Can you remember the difference from last month? If not, try altering line 20 of Program I to:

20 MODE 1

and then run the program.

That's right, Mode 5 gives you 20 characters per line and Mode 1 gives you forty. The colour numbers still refer to the same colours, though.

What happens if we alter it to a two colour mode? Change line 20 to:

20 MODE 0

You should only see "Colour 1" and "Colour 3" displayed, both in white. "Colour 2" has disappeared. This is because in this mode you have only two colours to play with, black and white.

As before, COLOUR 0 gives black. COLOUR 1 then has to be white. When it reaches COLOUR 2, the micro has run out of fresh colours so it goes back to black - hence the disappearance of "Colour 2".

The next colour is then white so Colour 3 appears as white. I think you can guess what COLOUR 4 and COLOUR 5 produce!

Now try Program II. At first glance this should produce the same results as Program I, this time using a loop. However, all is not as it seems, since it's in Mode 2, a 16 colour mode. Try running it and see.

10 REM *** PROGRAM II ***
20 MODE 2
30 FOR loop%=0 TO 3
40 COLOUR loop%
50 PRINT' "Colour ";loop%
60 NEXT loop%

COLOUR 1 still gives red, but COLOUR 2 now gives green, and COLOUR 3 yellow.

An important point coming up. These colour numbers do not mean fixed colours. As we've just seen, 2 is not always yellow, 3 not always white, and so on. The meaning of the colour numbers varies according to mode.

To sum up, the meaning of the colour numbers depends on the "logic" of the situation. So they are officially called logical colour numbers.

So, in the correct jargon, COLOUR 2 causes foreground text to be written in logical colour 2. As we have seen, in Mode 5 this is yellow, in Mode 2 it is green and in Mode 0 it is black.

The point is that logical colour numbers can be interpreted as different actual colours on the screen depending, for instance, on the mode.

To see all 16 colours in Mode 2, alter line 30 to:

30 FOR loop%=0 TO 15

and run it. Notice that it's 0 to 15 - this does in fact give 16 different colours!

The logical colours from 0 to 7 should be fairly obvious, but what's going on with all those flashing colours from 8 to 15?

Well, logical colour 8 flashes between black and white, logical colour 9 between red and cyan, and so on. If you can't make out all the pairs yourself. Figure I summarises them.

It may seem odd that there are two pairs flashing between black and white. This is because colour 8 flashes black then white, while colour 15 flashes white then black.

None too clear, is it? Program III should help.

10 REM *** PROGRAM III ***
20 MODE 2
40 PRINT TAB(0,12)"Colour 8"
45 COLOUR 15
50 PRINT TAB(0,13)"Colour 15'

This shows that while they flash between the same two colours, they are not in step. When colour 8 is showing white, colour 15 is showing black and vice versa. The same logic applies for the other flashing pairs.

One irritating point about Program III is the fact that it leaves text in colour 15 - everything you type in flashes! Most annoying!

You can stop this by entering:


after which the rest of the text will appear in red.

So far the logical colour numbers we've been using have changed the colour of the foreground text. Let's try altering the background colour.

Change mode with:


Then enter:


and then type in some random letters.

Hey presto, you still get white letters, but each individual letter is on a red background.

What happens is that if you want a red background to your numbers you simply add 128 to the logical colour number for red (1) and use the sum in the colour statement. Hence the use of COLOUR 129.

So, to put the letters on a yellow background you would use 128 plus 2, the logical colour for yellow. That is, COLOUR 130.

However, white letters on a yellow background look awful, so let's change the foreground text colour to red at the same time.



should have the desired effect.

Actually we could have achieved this by entering the one line:


The colon separating the two statements allows us to put them on the same line. It's the Basic equivalent of putting a full stop between sentences.



Can you work out how this gives you yellow foreground text on a red background?

Now, when we changed background colours, only the background of subsequent text characters has been altered.

At the moment the background colour is red. Try:


The whole screen is cleared to the background colour, so from now on your characters appear in a yellow foreground on a red background.

To prove that Colour 0 really does give a black foreground text - I'm sure you still doubt me - try:


and type away. All should be revealed!

10 REM *** PROGRAM IV ***
20 MODE 2
30 FOR loop%=0 TO 15
40 COLOUR loop%+128
50 CLS
60 PRINT TAB(0,15)"Background Colour";loop%+128
70 pause$=GET$
80 NEXT loop%
90 COLOUR 128
100 CLS

Program IV illustrates the background colours available. Each time through the loop (lines 30-80), the background colour is increased and line 40 chooses a new background colour (loop%+l28) as loop% increases each time through the loop, and line 50 clears the screen to this colour.

Line 60 prints out the new colour number for all the world to see, while line 70 introduces a pause, by waiting for a key to be pushed. The loop then takes you onto the next background colour.

Lines 90 and 100 are to ensure that you aren't left with an annoying flashing background when you drop out of the bottom of the loop.

10 REM *** PROGRAM V ***
20 MODE 2
30 FOR loop%=0 TO 15
40 background%=loop%+128
50 COLOUR background%:CLS
60 PRINT TAB(0,15)"Background Colour";background%
70 pause$=GET$
80 NEXT loop%

Program V does exactly the same as Program IV, and if you look carefully you'll see that it's equivalent - I've just used a variable (background%) instead of loop%+128 (it's calculated in line 40). I've also put the CLS on the same lines as the Colour statements (lines 50 50 and 90), separating them with colons.

Well, that's all for this month. I told you it was easy! More on colour next month.


Colour pair

Logical colour number

















Figure I: The logical colours' flashing pairs