COLOR

From QB64 Wiki
Revision as of 04:04, 16 June 2010 by imported>Clippy
Jump to navigation Jump to search

The COLOR statement is used to change the color of text and background in some SCREEN modes.


Syntax: COLOR [foreground%][, background%]


  • Background colors are available in SCREEN modes 0, 1, 7, 8 and 9. All other modes use a black background only. OUT can be used in non-DAC screen modes.
  • To change the background color only, use a comma and the color: COLOR ,background%
  • SCREEN 0 backgrounds can be changed each text character without affecting other text. Use CLS after a background color statement to create a fullscreen background color. 64 DAC hues with 16 high intensity blinking foreground (16 to 31) color attributes. QBasic will not flash in a window in NT, XP, VISTA or 7 (will flash in QB64).
  • SCREEN 1 has 4 background color attributes: 0 = black, 1 = blue, 2 = green, 3 = grey. White foreground color only.
  • SCREEN 2 is white forecolor with black background and cannot use the COLOR statement!
  • SCREEN 7 can use 16 (DAC) colors with background colors. RGB settings can be changed in colors 0 to 7 using OUT.
  • SCREEN 8 has 16 color attributes with 16 background colors.
  • SCREEN 9 can use up to 64 DAC color hues in 16 color attributes with background colors assigned to attribute 0 with a PALETTE swap. RGB settings can be changed in colors 0 to 5 and 7 using OUT
  • SCREEN 10 has only 4 color attributes, black background. COLOR 0 = black, 1 = grey, 2 = flash white and 3 = bright white.
  • SCREEN 11 is white forecolor with black background and cannot use the COLOR statement!
  • SCREEN 12 can use 16 color attributes, black background. 256K possible RGB hues.
  • SCREEN 13 can use 256 color attributes, black background. 256K possible RGB hues.
  • Non-DAC color RGB shades can be changed using OUT. DAC screens 0, 7 and 9 color changes are limited!
  • PALETTE swap changes of RGB values are allowed in DAC screens 7 and 9.
  • _DEST can be used with COLOR to change the image color using QB64.



Basic's 16 Default Color Attributes (non-DAC)
 Attribute       Description      Red   Green    Blue
 0 ............ Black ........... 0 ...... 0 ........ 0
 1 ........... Dark Blue ...... 0 ...... 0 ....... 42
 2 .......... Dark Green ..... 0 ..... 42 ....... 0
 3 ........... Dark Cyan ..... 0 ..... 42 ...... 42
 4 ............ Dark Red ..... 42 ..... 0 ........ 0
 5 .......... Dark Violet .... 42 ..... 0 ....... 42
 6 .......... Dark Yellow ... 42 .... 21 ....... 0
 7 .......... Dark White .... 42 .... 42 ...... 42
 8 ........... Dark Grey .... 21 .... 21 ...... 21
 9 ............... Blue ........ 21 .... 21 ...... 63
10 ............. Green ....... 21 .... 63 ...... 21
11 .............. Cyan ....... 21 .... 63 ...... 63
12 .............. Red ......... 63 .... 21 ...... 21
13 ............. Violet ....... 63 .... 21 ...... 63
14 ............. Yellow ...... 63 .... 63 ...... 21
15 ............. White ....... 63 .... 63 ...... 63


Summary: The red, green, and blue values can be changed using OUT or PALETTE statements. Values from 0 to 63. Only some attribute RGB color values can be changed in DAC SCREEN modes and the DAC RGB settings may be different.

Color Port access using OUT
OUT &H3C7, attribute : Set port to read RGB settings
color_intensity = INP(&H3C9) 'reads present setting
OUT &H3C8, attribute : Set port to write RGB settings
OUT &H3C9, color_intensity : Writes new settings
  • Every 3 reads or writes, changes to next color attribute
  • Color setting is Red, Green and Blue intensities in ascending order
  • Color attribute intensity values range from 0 to 63 only

Example 1: Reading the default RGB color settings of color attribute 15.

OUT &H3C7, 15 red% = INP(&H3C9) green% = INP(&H3C9) blue% = INP(&H3C9) PRINT red%, green%, blue%

63 63 63

Example 2: Changing the color settings of attribute 0 (the background).

OUT &H3C8, 0 OUT &H3C9, 0 'red OUT &H3C9, 0 'green OUT &H3C9, 30 'blue


Example 3: Printing in fullscreen SCREEN 0 mode with a color background under the text only.

SCREEN 12: SCREEN 0 ' used for fullscreen instead of window COLOR 30, 6: LOCATE 12, 4: PRINT "Hello!"

Result: Hello! is printed in flashing high intensity yellow with brown background behind text when in fullscreen.

Example 4: Using CLS in SCREEN 0 to make fullscreen background color.

SCREEN 12: SCREEN 0 COLOR , 7: CLS COLOR 9: PRINT "Hello"




See also: PRINT, LOCATE, SCREEN

POINT, SCREEN (function), OUT, INP, PALETTE




Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page