Contents / Part 2 / Previous chapter / Next chapter / Index


8 Introducing graphics

Modes, Colours, Graphics and Windows

The Model A BBC computer can display text and graphics in four different modes; the Model B can show eight different modes. Only one mode can be used at a time. The Teletext Mode (MODE 7) differs from all the other modes in many ways and a whole chapter has been devoted to that mode (see page 150). In particular it is not easy to draw lines or triangles in MODE 7 and the colour of the text is changed in a special way. Finally some characters are displayed on the screen differently in this mode - for example the character [ is displayed as the symbol for 1/4.

On the Model A there are two modes in which graphics can be used (MODE 4 and MODE 5). With a Model B five graphics modes are available. The description which follows will assume that you are in MODE 5. To reach it, simple type MODE 5 and press RETURN. Note that pressing BREAK will return you to MODE 7 so avoid using BREAK - the "panic button" is marked ESCAPE. If you press this the computer will stop what it is doing and return control to you. MODE 5 is a four colour mode which means that up to four different colours can be shown on the screen at any time. When you enter MODE 5 two "colours" are displayed - white letters on a black background. As you will be aware from earlier chapters the colour of the text can be changed with the COLOUR statement, and since this is a four colour mode you can select from

COLOUR 0 black

COLOUR 1 red

COLOUR 2 yellow

COLOUR 3 white

The same four colours (black, red, yellow and white) may be selected for the background with the commands

COLOUR 128 (128+0) black

COLOUR 129 (128+1) red

COLOUR 130 (128+2) yellow

COLOUR 131 (128+3) white

The COLOUR statement can be used to change the colour of the text foreground and background - but not the colour of any graphics: for that you need to use another caste keywords - GCOL, which stands for Graphics COLour.

Graphics

For the graphics: when drawing lines and triangles, positions on the screen are given with two numbers (the x and y co-ordinates).

The point A has co-ordinates 600 across, 0 up

The point B is at position 100,500 and C is at 800,%0

The statement

DRAW 800, 800

will draw a line from the last point 'visited' to 800,800. If no point has been visited, the computer will assume that it starts from the point 0,0.

To move without drawing a line use the command MOVE. So to draw a line from 1000,0 to 1000,1000 type

MOVE 1000,0

DRAW 1000,1000

DRAW 100,500 will draw another line, and so on. As well as MOVE and DRAW there are PLOT commands for other effects.

These are described in a later chapter. The statement GCOL is used to change the graphics colour used by the DRAW statement. GCOL is followed by two numbers, the first is normally zero and the second determines the graphics colours e.g.

GCOL 0,0 black lines

GCOL 0,1 red lines

GCOL 0,2 yellow lines

GCOL 0,3 white lines

We'll consider what happens when the first number is not zero later on (page 167).

As with the text colours, one can change both foreground and background colours. However, before that can be illustrated it will be easier to set up two 'windows' on the screen - one for text and one for graphics so that you can be quite clear which is which. We will then return to the GCOL statement.

Windows

At the moment the whole screen can be used for text and the whole screen can be used for graphics. In some modes (eg MODE 5) we can restrict each to a specific "window" - or section of the screen. In modes without graphics (MODES 3, 6 and 7) only text windows can be used. Imagine we want to create two windows as shown below - on the left a graphics window; on the right a text window. Suppose that the text window stretches from the top of the screen right to the bottom but the graphics window stops short of the bottom:

a Making a graphics window

Imagine a graphics window which has its edges a, b, c and d 'graphics units' away from the bottom left hand corner of the screen (which is always the starting point for graphics).

The statement VDU 24 is used (with some numbers after it) to set up a graphics window (VDU stands for Visual Display Unit). For the window shown above the full statement is

VDU 24,a;b;c;d;

Note: the comma after 24 and the semi colon after all the other values. The reason for this punctuation is given on page 386. So for our actual graphics window we would put

VDU 24, 0;100;300;1000;

In all screen modes which can support easily defined graphics the range of values for a, b, c and d is always the same; 0-1023 vertically, 0-1279 horizontally.

b Making a text window

Unlike graphics, text 'starts' at the top left hand corner of the

screen, so text windows are defined using that point as zero.

Imagine the text window has edges a, b, c and d 'text units' away from the top left of the screen, as shown:

The statement VDU 28 is used to setup the window as follows

VDU 28,a,b,c,d

Note: the comma after the 28 and between the other values. There is no comma at the end.

For the text window we wanted to set up, the statement would be

VDU 28,5,31,19,0

To prove that we now have two separate windows try

COLOUR 129

CLS

to fill the text window with red and

GCOL 0,130

CLG

to fill the graphics window with yellow.

Note: In the various different screen modes the number of text characters which can be accommodated along the screen and down the screen is also different. This affects the range of values for the horizontal distances a and c as follows:

MODES 0 and 3 (which support 80 characters to the line)

0 to 79

MODES 1, 4, 6 and 7 (which support 40 characters to the line.)

0 to 39

MODES 2 and 5 (which support 20 characters to the line)

0 to 19

Similarly the values of b and d depend on the mode.

MODES 0,1,2,4 and 5 have 32 lines (0 to 31)

MODES 3,6 and 7 have 25 lines (0 to 24)

To recap, to set up the windows press BREAK then type the following - with RETURN at the end of each line. You are working in command mode rather than writing a program, so the computer acts on each instruction as you press RETURN. It also means that pressing BREAK in the middle of what follows would destroy the text and graphics windows and send the computer back to MODE 7.

MODE 5

VDU 24,0;100;300;1000;

VDU 28,5,31,19,0

CLS

The command CLS clears the text from the screen. Now try typing the following lines

DRAW 0,1000

DRAW 100,1000

DRAW 0,0

DRAW 1000,1000

You will find that text is now only appearing in the text window and that graphics are only appearing in the graphics window. If you want to clear the text only, type CLS. It you want to clear the graphics only, type CLG. (Normally CLS clears the whole screen, but where independent text and graphics areas are defined, CLS only clears the text.) You will also notice that although some of the commands have told the computer to draw in areas of the screen outside the graphics window it has not done so visibly.

Windows may overlap - in fact when you change MODE both the text and graphic windows fill the whole screen, and you can move windows without destroying what is on the screen, although changing story does clear the screen. To reset both text and graphics windows to the whole screen, e.g, in the middle of a program, use VDU 26.

VDU 5 enables text to be drawn at any position inside a graphics window - see pages 49, 74 and 379.

Changing the colours of text and graphics

Now back to text and graphic colours. Let us define the text background to be red and the graphics background to be yellow.

COLOUR 129 red text background

GCOL 0,130 yellow graphics background,

and then clear the text and graphics areas to their background colours.

CLS clear text area

CLG clear graphics area

Now to select the foreground colours for the two areas - for example to obtain yellow letters (text foreground) type

COLOUR 2 and to get black graphics lines type

GCOL 0,0

Test this out by typing

DRAW 150,500

Although you start up (in MODE 5) with the four colours set to black, red, yellow and white, you can select other colours (still of course only 4 at a time) by using VDU 19, as we saw on page 10. See page 382 for mare details of VDU 19.

So far we have been working in command mode. Next try typing in this program. You can use MODE 7 to type the program in but nothing will happen until you run the program. So, press BREAK and then the following

10 MODE 5

20 VDU 24, 0; 0; 500; 1000;

30 VDU 28,10,20,19,5

40 COLOUR 129

50 COLOUR 2

60 GCOL 0,130

70 CLS : CLG

80 FOR N=1 TO 1000

90 PRINT "LINE"; N

100 GCOL 0, RND (4)

110 DRAW RND(500), RND(1000)

120 NEXT N

RUN

You might like to try saving this program on cassette as described in section 5.

Exit: BBC Microcomputer User Guide; Kasoft Typesetting; Archer


The BBC Microcomputer User Guide was written by John Coll and edited by David Allen for the British Broadcasting Corporation.

Optical character recognition and original formatting effort by Mark Usher.

HTML version maintained by: Kade "Archer" Hansson; e-mail: archer@dialix.com.au

Last updated: Monday 12th February 2001