reading_20the_20palette_20contents
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| reading_20the_20palette_20contents [2018/03/31 13:19] – external edit 127.0.0.1 | reading_20the_20palette_20contents [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| =====Reading the palette contents===== | =====Reading the palette contents===== | ||
| - | //by Richard Russell, October 2011//\\ \\ In BBC BASIC you can change the contents of the colour palette using either [[http:// | + | //by Richard Russell, October 2011//\\ \\ In BBC BASIC you can change the contents of the colour palette using either [[http:// |
| + | |||
| + | <code bb4w> | ||
| DIM palette{(15)r&, | DIM palette{(15)r&, | ||
| - | Then each time you modify the palette you update the local copy as well:\\ | + | </ |
| + | |||
| + | Then each time you modify the palette you update the local copy as well: | ||
| + | |||
| + | <code bb4w> | ||
| COLOUR i, r, g, b | COLOUR i, r, g, b | ||
| palette{(i)}.r& | palette{(i)}.r& | ||
| palette{(i)}.g& | palette{(i)}.g& | ||
| palette{(i)}.b& | palette{(i)}.b& | ||
| - | If the palette is modified from many places in your program you would probably want to put this code in a procedure.\\ \\ However you may consider the overhead of keeping a local copy unattractive. In that case you can alternatively read the palette contents using the Windows API. To read a single palette entry use code similar to the following:\\ | + | </ |
| + | |||
| + | If the palette is modified from many places in your program you would probably want to put this code in a procedure.\\ \\ However you may consider the overhead of keeping a local copy unattractive. In that case you can alternatively read the palette contents using the Windows API. To read a single palette entry use code similar to the following: | ||
| + | |||
| + | <code bb4w> | ||
| SYS " | SYS " | ||
| - | Here **index%** is the palette index (0-15) and the current value is returned in the variable **rgb%**. \\ \\ Alternatively you could read the entire 16 entries at once, for example into an array:\\ | + | </ |
| + | |||
| + | Here **index%** is the palette index (0-15) and the current value is returned in the variable **rgb%**. \\ \\ Alternatively you could read the entire 16 entries at once, for example into an array: | ||
| + | |||
| + | <code bb4w> | ||
| DIM rgb%(15) | DIM rgb%(15) | ||
| SYS " | SYS " | ||
| - | In both cases the returned value contains the red component in bits 0 to 7, the green in bits 8 to 15 and the blue in bits 16 to 23. You could separate them out as follows:\\ | + | </ |
| + | |||
| + | In both cases the returned value contains the red component in bits 0 to 7, the green in bits 8 to 15 and the blue in bits 16 to 23. You could separate them out as follows: | ||
| + | |||
| + | <code bb4w> | ||
| rgb% = rgb%(index%) : REM Needed only in the second case | rgb% = rgb%(index%) : REM Needed only in the second case | ||
| r = rgb% AND &FF | r = rgb% AND &FF | ||
| g = (rgb% >> 8) AND &FF | g = (rgb% >> 8) AND &FF | ||
| b = (rgb% >> 16) AND &FF | b = (rgb% >> 16) AND &FF | ||
| + | </ | ||
reading_20the_20palette_20contents.1522502377.txt.gz · Last modified: 2024/01/05 00:16 (external edit)