So we drew a green box, woohoo! But why was it green? The Spectrum has 8 core colours: Black, Blue, Red, Magenta, Green, Cyan, Yellow, and White, and those can be used individually for the background (referred to in BASIC as ‘PAPER’), and foreground (INK), of a square on the screen – which are arranged as 24 rows of 32 columns.
I did promise you 15 colours in the title though, and that is done by making the colour ‘Bright’. You might think that would make 16 colours, but even a bright black looks, erm, pretty black.
And finally, you can elect to have the square swap the foreground and background colours around every few seconds – by making it ‘Flash’. A great example of this can be seen on the loading screen to Manic Miner.
All the combinations of this – 2 lots of 8 colours, with bright and/or flashing – can be stored in a single byte using the following calculation:
Combined value = INK + (PAPER * 8) + (BRIGHT? * 64) + (FLASH? * 128)
With each colour being assigned a number:
0 = BLACK 1 = BLUE 2 = RED 3 = MAGENTA 4 = GREEN 5 = CYAN 6 = YELLOW 7 = WHITE
So our value of 32 is made up of black INK, green PAPER, no BRIGHT, and no FLASH, as that is 0 + (4*8) + (0*64) + (0*128) = 32
You might have tried changing that value, for example to 33, and found that nothing happened – and that was because there wasn’t actually anything under the square, so the foreground colour wasn’t seen. We’ll fix all that shortly, and fill the screen with colour…