PALETTE: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 27: Line 27:
   {{Cl|SCREEN (statement)|SCREEN}} 9 ' background is default black
   {{Cl|SCREEN (statement)|SCREEN}} 9 ' background is default black
   {{Cl|LOCATE}} 20, 33: {{Cl|PRINT}} "Press any Key!"   
   {{Cl|LOCATE}} 20, 33: {{Cl|PRINT}} "Press any Key!"   
   {{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} 63
   {{Cl|FOR...NEXT|FOR}} i = 0 {{Cl|TO}} 63
   a$ = {{Cl|INPUT$}}(1) ' wait for a keypress
   a$ = {{Cl|INPUT$}}(1) ' wait for a keypress
   {{Cl|PALETTE}} 0, i
   {{Cl|PALETTE}} 0, i

Revision as of 22:16, 3 May 2022

The PALETTE statement can swap color settings, set colors to default or set the red, green and blue color components of palette colors.


Syntax

PALETTE [attribute%, red% + (green% * 256) + (blue% * 65536)]
PALETTE [existingAttribute%, newAttribute%]


Description

  • red%, green% and blue% values can range from 0 to 63. Many color shades are possible in non-DAC color attributes.
  • If the red%, green% and blue% color intensity settings are all the same value the resulting color is a shade of grey.
  • A swap is often used with DAC color attributes that cannot change RGB settings. Only the RGB color settings are swapped from original existingAttribute% to newAttribute%. Screens 0 thru 9 support swaps. Screen 10 supports up to attribute 8 only.
  • PALETTE without any value sets any changed RGB settings back to the default color settings, including DAC colors.
  • PALETTE USING can be used when color intensity values are stored in an array.
  • QB64 implements the _PALETTECOLOR statement to provide extended palette functionality.


QBasic/QuickBASIC

  • Screens 0, 7 and 9 (DAC) colors could not be changed using the first syntax, but the program could use OUT to change intensity settings of attributes 1 thru 5.


Examples

Example: Displaying all 64 DAC color hues as backgrounds in SCREEN 9 using a PALETTE swap.

  
  SCREEN 9 ' background is default black
  LOCATE 20, 33: PRINT "Press any Key!"  
  FOR i = 0 TO 63
   a$ = INPUT$(1) ' wait for a keypress
   PALETTE 0, i
  NEXT  
Note: Other attributes (1 to 15) can also be swapped for DAC foreground colors.


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link