using_20larger_20colour_20palettes
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
using_20larger_20colour_20palettes [2018/03/31 13:19] – external edit 127.0.0.1 | using_20larger_20colour_20palettes [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
=====Using larger colour palettes===== | =====Using larger colour palettes===== | ||
- | //by Richard Russell, July 2010//\\ \\ By default, //BBC BASIC for Windows// uses a colour **palette** of 16 colours. It must be emphasised that this doesn' | + | //by Richard Russell, July 2010//\\ \\ By default, //BBC BASIC for Windows// uses a colour **palette** of 16 colours. It must be emphasised that this doesn' |
+ | |||
+ | <code bb4w> | ||
ncols% = 128 | ncols% = 128 | ||
DIM lp{palVersion{l&, | DIM lp{palVersion{l&, | ||
Line 14: | Line 16: | ||
@hpal% = hpal% | @hpal% = hpal% | ||
SYS " | SYS " | ||
- | Having created a new palette we can select a [[http:// | + | </ |
+ | |||
+ | Having created a new palette we can select a [[http:// | ||
+ | |||
+ | <code bb4w> | ||
VDU 23, | VDU 23, | ||
- | For the purposes of the example the window (client) dimensions have been set to 640x512 and the character size to 8x16 pixels; other values could be used instead. Note that the number of colours should always be set to a power-of-two (e.g. **32**, **64** or **128**).\\ \\ Only the first 16 palette entries will be initialised (to the normal set of default colours) so the remaining entries need to be defined as required. This is done in the usual way with the **COLOUR** statement:\\ | + | </ |
+ | |||
+ | For the purposes of the example the window (client) dimensions have been set to 640x512 and the character size to 8x16 pixels; other values could be used instead. Note that the number of colours should always be set to a power-of-two (e.g. **32**, **64** or **128**).\\ \\ Only the first 16 palette entries will be initialised (to the normal set of default colours) so the remaining entries need to be defined as required. This is done in the usual way with the **COLOUR** statement: | ||
+ | |||
+ | <code bb4w> | ||
FOR I% = 16 TO ncols%-1 | FOR I% = 16 TO ncols%-1 | ||
R% = RND(256)-1 | R% = RND(256)-1 | ||
Line 23: | Line 33: | ||
COLOUR I%,R%,G%,B% | COLOUR I%,R%,G%,B% | ||
NEXT | NEXT | ||
- | Here the palette has been loaded with random colours; this is unlikely to be what you will want in practice!\\ \\ Finally we can draw coloured text or graphics in the usual way, except that we can use colour numbers (palette indices) from zero to one less than the size of the palette. For example:\\ | + | </ |
+ | |||
+ | Here the palette has been loaded with random colours; this is unlikely to be what you will want in practice!\\ \\ Finally we can draw coloured text or graphics in the usual way, except that we can use colour numbers (palette indices) from zero to one less than the size of the palette. For example: | ||
+ | |||
+ | <code bb4w> | ||
FOR I% = 0 TO ncols%-1 | FOR I% = 0 TO ncols%-1 | ||
COLOUR I% | COLOUR I% | ||
PRINT " | PRINT " | ||
NEXT | NEXT | ||
- | It is theoretically possible to extend this technique to use a 256-colour palette, but since BBC BASIC uses colour values 128-255 to indicate **background** colours it is not possible to use the regular **COLOUR**, **GCOL** or **VDU** statements to set the colour in this case. For example to set the text foreground colour use:\\ | + | </ |
+ | |||
+ | It is theoretically possible to extend this technique to use a 256-colour palette, but since BBC BASIC uses colour values 128-255 to indicate **background** colours it is not possible to use the regular **COLOUR**, **GCOL** or **VDU** statements to set the colour in this case. For example to set the text foreground colour use: | ||
+ | |||
+ | <code bb4w> | ||
@vdu.t.c& | @vdu.t.c& | ||
SYS " | SYS " | ||
+ | </ |
using_20larger_20colour_20palettes.1522502389.txt.gz · Last modified: 2024/01/05 00:16 (external edit)