Adjusting the palette in BASIC
mikko (3145) 120 posts |
I want to adjust the palette in BASIC using the format of the COLOUR command COLOUR x, r, g, b where x is the logical colour number and r, g, b are the red green and blue values of the colour respectively. This was discussed on another thread recently but I must be missing a simple concept so I’ve asked this question anew and I’d be really grateful if anyone can explain why I don’t get the colours I expect in the last two examples in the following code snippet. MODE "X1920 Y1020 C16M" ORIGIN 200, 200 REM set graphics colour to teal GCOL 0, 128, 128 RECTANGLE FILL 50, 0, 50, 50 REM displays a teal square, just as I'd expect REM set graphics colour to palette 1 - red GCOL 1 RECTANGLE FILL 100, 0, 50, 50 REM displays a red square, just as I'd expect REM attempt to set palette 1 to "teal" COLOUR 1, 0, 128, 128 REM set graphics colour to palette 1, including the OF keyword GCOL OF 1 RECTANGLE FILL 150, 0, 50, 50 REM why is this square black and not teal? REM set graphics colour to palette 1, omitting the OF keyword GCOL 1 RECTANGLE FILL 200, 0, 50, 50 REM why is this square red and not teal? |
Jeffrey Lee (213) 6046 posts |
The palette manipulation commands alter the physical palette – i.e. the palette which the video hardware uses to look up the colour of each pixel as it generates the video signal. Only modes with <= 256 colours have a physical palette. With higher colour depths (“true colour” modes), no palette is used by the hardware, and instead each pixel specifies its RGB value directly. In these modes any attempt to write the palette is ignored. But for backwards-compatibility commands like |
mikko (3145) 120 posts |
Ah, super. That makes sense. Thanks, Jeffrey. This now works: MODE "X1920 Y1020 C256" ORIGIN 200, 200 REM attempt to set palette 1 to "teal" COLOUR 1, 0, 128, 128 REM set graphics colour to palette 1, including the OF keyword GCOL OF 1 RECTANGLE FILL 0, 0, 50, 50 REM Teal Square. Nice. Maybe these limitations are mentioned elsewhere in the manual but I think they could usefully be mentioned or alluded to in the descriptions of COLOUR and/or GCOL as well. In particular the nuanced use of “OF” seems crucial but is not mentioned in the relevant description of GCOL: [2] GCOL [OF [expr1,]expr2] [ON [expr3,]expr4] ... The parameters following OF are used to set the graphics foreground colour and those following ON are used to set the graphics background colour. expr1 and expr3, if specified are the plot 'action' as described above and expr2 and expr4 are colour numbers. Hence my confusion about how using a palette number via GCOL could be done. |