Practice your coding with the BASin coding teacher.
Try to code at least one program using the five codewords you have learned in this lesson, and any other codewords you have learned from the previous lessons.
In this lesson you will learn how to use colours to design what appears on the computer screen the way you want it to look.
PAPER –You can think of the background of your computer screen as being like a big sheet of paper. You can choose the colour of this background by using the PAPER codeword. This codeword tells the computer which colour you want to choose for the screen background. There are 8 colours to choose from.
INK – When you want to write or draw something on the computer screen you need to decide what colour to use for the writing or drawing. The INK codeword tells the computer which colour you want to choose for whatever you decide to write or draw on the screen background. There are 8 colours to choose from.
BORDER – You might want to make your screen background look a little neater by putting a border around the edge of it. The BORDER codeword tells the computer which colour you want for the border around the edge of the background.
CLS – Sometimes you will want your program to clear the screen and to design a new screen for the next part of the program. The CLS codeword means “CLear Screen” – it tells the computer to delete (which means the same as “clear”) everything which is now on the screen, ready for a new screen design.
PRINT – Whenever you want the computer to write or draw something on the screen you need to use the PRINT codeword. Just as you can think of the computer screen as being like a big sheet of paper, you can think of writing or drawing being a bit like printing something on paper, or writing it with a pen or pencil.
The PAPER codeword is a statement/command.
You will use the PAPER codeword to choose the colour of the paper or background that you want to use for the screen display.
When you use the PAPER codeword you must put a number after it. For example, if your program has the line:
80 PAPER 6
it means that on line 80 of your program you are choosing colour number 6, which is yellow.
In addition to black and white there are 8 other colours to choose from:
3 Magenta (also called Purple)
5 Cyan (a mixture of Blue and Green)
8 No change
9 Contrasting Black or White
A note about colours 8 (No change) and 9 (Contrasting Black or White) – if you set an INK or PAPER to 8, then when the letters are drawn on the screen, they keep the colours that are already there. This way you can keep, say, the paper colour but change the ink that is used to draw letters and numbers.
Colour 9 is “contrasting” which means that for a dark PAPER, a light INK will be chosen for you by the Spectrum. And of course, a light PAPER will give you a dark INK. This also works for a PAPER 9, which will change the PAPER colour depending on if you have a light or dark INK.
For example, if you tell the Spectrum to PRINT INK 6; PAPER 9;”Hello!” then the word “Hello!” will appear with yellow writing, but on a black paper.
If you want to tell the computer to produce a coloured background all over the whole screen display area, you must use the CLS codeword on the next line of your program after the PAPER codeword, like this:
10 PAPER 4
The computer will then clear the whole of the screen display area and replace it by the colour you have chosen with the PAPER codeword, which is green in this example (colour 4). So that colour will now be the background colour for the screen display area.
The INK codeword is command.
You will use the INK codeword to choose the colour in which the letters, numbers and other characters are displayed on the screen, also the colour for any lines and curves that you draw on the screen and any points that you plot. (You will learn how to draw lines and circles and to plot points in later lessons.)
When you use the INK codeword you must put a number after it. For example, if your program has the line:
70 INK 4
it means that on line 70 of your program you are choosing colour number 4, which is green, for whatever your program writes or draws on the screen. This is just like you choosing the colour of a pen or a crayon when you draw on paper.
3 Magenta (Purple)
5 Cyan (Blue-Green)
9 Contrasting Black or White
INK 8 specifies that the existing colour remains unchanged at any position on the screen where INK 8 is used. INK 9 causes the ink colours to be either black or white so that it shows up against the paper (background) colour.
The BORDER codeword is a statement/command.
BORDER chooses the colour of the border around the screen display area. The same colour is used for the paper colour of the lower part of the screen.
When you use the BORDER codeword you must put a number after it. For example, if your program has the line:
30 BORDER 7
it means that on line 30 of your program you are choosing colour number 7 for the colour of the border.
The CLS codeword is a command.
CLS clears all text and graphics from the display area so it will be leaving blank, in the current colour of the paper (the “background” colour).
CLS may be used as a direct codeword or it may form a statement in a program. This means that you can type it in without a line number (a direct codeword) and when you press ENTER it will be executed immediately. If it’s part of a statement in a program then it will be stored for later.
When CLS is used it clears the display area (but not the border).
CLS always clears to the colour last set by the PAPER command. If no PAPER command has been issued previously, then it will use white, which is the default at power-on. No matter how long ago you changed the PAPER, the spectrum will remember it and use it for CLS.
PAPER 6: CLS
Will change your screen to yellow.
On its own will use the last PAPER colour you chose, which in this case is yellow – so the screen will be wiped clean, but in a yellow colour.
If you want to have a coloured background over the whole display area you must use the CLS codeword after a PAPER codeword and before a PRINT codeword or any other codeword which displays something (for example CIRCLE or DRAW).
The PRINT codeword is a statement/command.
The PRINT codeword tells the computer to display data on the screen. The data may be any single character like a letter or a digit, or it can be a sequence of characters.
PRINT may be used alone or it may be followed by data.
Using PRINT with one item of data looks like this:
80 PRINT 36
This will display the number 36.
When you use PRINT with two or more separate items of data you must put a semicolon, or a comma or an apostrophe between them. For example:
81 PRINT 36, 37, 38
will display 36 37 38
You can display whatever characters you like by putting them between a pair of quotation marks, like this:
82 PRINT “My name is David”
will display My name is David
83 PRINT “3/542/76/32”
will display 3/542/76/32
If you use PRINT followed by a numeric expression the computer will display the value of that numeric expression. For example:
84 PRINT 8/2
will display 4 because the value of the expression 8/2 is 4.
You can use the PRINT codeword followed by one of the colour codewords to affect the colour of what you are telling the computer to display. You do this by putting a semicolon (;) after the colour codeword but before the data that you want to display. For example:
85 PRINT INK 2; house
will print the word house using ink colour 2 (which is red).
Other colour codewords that you will learn about in these lessons and which you can use after the PRINT codeword are: PAPER, FLASH and BRIGHT.
This a simple program to display a message on the screen. Lines 10 to 40 clear the screen and select the colours for the ink, paper and border. Line 50 displays the message.
10 CLS 11 REM Clear the screen 20 BORDER 2 21 REM Choose colour 2 (blue) 22 REM for the border 30 PAPER 7 31 REM Choose colour 7 (white) 32 REM for the paper" 40 INK 0 41 REM Choose colour 0 (black) 42 REM for the ink 50 PRINT "Hello world" 51 REM Display "Hello world"