2.0 Introduction
2.1 Available colours
2.2 Setting foreground and background colour for text
2.3 Activities
2.4 Setting foreground and background colours for graphics
2.5 Activities
Colour livens up any graphics display! It makes the display more attractive and it adds meaning by making features stand out. The BBC Microcomputer is particularly renowned for its colour graphics, and this chapter shows how to make full use of them. You will of course find it best to have a colour television or {monitor, but even with a black and white one, displays should be Improved by being in various shades of grey, rather than just black and white.
The BBC Microcomputer is often said to offer a maximum of sixteen colours. This is not strictly true, Actually only eight colours are 'available, but they can be either flashing or non-flashing - which gives sixteen options. Table 2.1 lists what we call their 'absolute colour numbers'. We describe these numbers as absolute because they cannot be changed. They are always the same irrespective of the mode. This is in contrast to the colour numbers which appear in the various statements that set colour, where you can set the colour given by a particular number, Although it may seem confusing to have two sets of colour numbers, redefining colours does allow some very attractive and sophisticated graphics programming, which we discuss in Chapter 5.
0 | = black | 8 | = flashing black/white |
1 | = red | 9 | = flashing red/cyan |
2 | = green | 10 | = flashing green/magenta |
3 | = yellow | 11 | = flashing yellow/blue |
4 | = blue | 12 | = flashing blue/yellow |
5 | = magenta | 13 | = flashing magenta/green |
6 | = cyan | 14 | = flashing cyan/red |
7 | = white | 15 | = flashing white/black |
Table 2.1 The absolute colour numbers
In this chapter we deal with default colour numbers, i.e. with colour numbers as they are if you take no steps to redefine them. The default colour associated with any colour number depends on the mode - which is of course not true of an absolute colour, For example, in modes 0 and 4, which are the so-called two colour modes, the default colour numbers represent the to following colours:
colour 0 = black
colour 1 = white
Whereas in modes 1 and 5 the default colour numbers represent the following colours:
colour 0 = black
colour 1 = red
colour 2 = yellow
colour 3 = white
The full range of sixteen colours is available only in mode 2, where the colour numbers are initially set equal to the absolute colour number.
When setting the colour of graphics displays, BBC BASIC requires you to distinguish between foreground and background colours. There can be only one background colour, but there can be as many foreground colours as you wish to program - provided of course that you are in a mode which allows that many colours. The statement for setting text colour is COLOUR, followed by the colour number,
For the foreground the colour is merely as given above, for the particular mode. For the background, however, the colour number is obtained by adding 128 to the normal colour numbers. By way of illustration, the following three lines of program set 5 as the graphics mode, yellow as the foreground colour and red as the background colour of any text to follow:
10 MODE 5
20 COLOUR 2 :REM foreground = yellow
30 COLOUR 129 :REM background = red
40 CLS
Line 10 sets the mode and, in so doing, clears the screen to black and resets all the colours to their default values. Lines 20 and 30 set up new values for the foreground and background colours but only for any future writing to the screen. In line 40 the statement CLS - meaning 'clear screen' - clears the screen to the background colour of red.
Enter each of the following commands in the direct mode and note the colours that you get on the screen, particularly the foreground colour (the colour of the writing) and the background colour.
MODE 5
COLOUR 1
COLOUR 2
COLOUR 3
COLOUR 129
COLOUR 130
COLOUR 0
COLOUR 131
Have the table of colours for mode 5 alongside you and make sure that you can explain the colours of each of the lines of writing, both foreground and background. Do you see that the colour numbers affect only the writing which follows? They leave previous writing unaltered.
The GCOL statement sets the colour for graphics - or, to be more precise, one form of the GCOL statement sets the colour for graphics. This form is GCOL 0,C and we will not mention the other forms yet. The GCOL 0,C form is the graphics equivalent of the COLOUR statement, in that it controls both the foreground and background colours and affects the colour of the graphics operations that follow its execution. C is the colour number - but you should bear in mind that the GCOL statement, like the other statements for colour, takes the redefinable colour, not the absolute colour.
Provided C has a value between 0 and 15 (depending on mode), it sets foreground i.e. the colour of what you draw on the screen.
To set the background colour, obtain a value for C by adding 128 to the number of the colour that you want. Again, the range of values available depends on the mode. Next use GCOL 0,C. Then, when you clear the screen using the statement CLG, which stands for 'Clear Graphics', the background colour changes accordingly. For example, setting the screen to red for either of the four-colour modes would require the following lines:
10 MODE 5
20 GCOL 0,129 :REM (128+1)
30 CLG
. . . .
You could now set a yellow foreground by a line such as:
40 GCOL 0,2
i. See the effects of setting the foreground and background colours for graphics by entering the following in direct mode:
MODE 5
GCOL 0,129
CLG
GCOL 0,2
DRA W 500,500
GCOL 0,0
DRAW 1280,500
GCOL 0,3
DRAW 500,1000
With a black and white television, you may need to adjust the contrast to distinguish the various shades of grey which correspond to the colours.