mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-09-07 09:30:15 +00:00
197 lines
10 KiB
Text
197 lines
10 KiB
Text
|
{{QBDLDATE:05-20-2022}}
|
||
|
{{QBDLTIME:23:12:21}}
|
||
|
The [[COLOR]] statement is used to change the foreground and background colors for printing text.
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
: [[COLOR]] [{{Parameter|foreground&}}][, {{Parameter|background&}}]
|
||
|
|
||
|
|
||
|
{{PageDescription}}
|
||
|
* {{Parameter|background&}} colors are available in all QB64 color SCREEN modes.
|
||
|
* [[SCREEN]] mode 10 has only 3 white foreground attributes including flashing.
|
||
|
* To change the {{Parameter|background&}} color only, use a comma and the desired color. Ex: [[COLOR]] , {{Parameter|background&}}
|
||
|
* Graphic drawing statements like [[PSET]], [[PRESET]], [[LINE]], etc, also use the colors set by the [[COLOR]] statement if no color is passed when they are called.
|
||
|
* The [[$COLOR]] metacommand adds named color constants for both text and 32-bit modes.
|
||
|
|
||
|
|
||
|
==Screen Mode Attributes==
|
||
|
* '''SCREEN 0''' {{Parameter|background&}} colors 0 to 7 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. See [[_BLINK]].
|
||
|
** See example 7 below for more SCREEN 0 background colors.
|
||
|
* '''SCREEN 1''' has '''4 background color attributes''': 0 = black, 1 = blue, 2 = green, 3 = grey. White foreground color only.
|
||
|
* '''SCREEN 2''' is '''monochrome''' with white forecolor and black background.
|
||
|
* '''SCREEN 7''' can use 16 ([[DAC]]) colors with background colors. RGB settings can be changed in colors 0 to 7 using [[_PALETTECOLOR]].
|
||
|
* '''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 [[_PALETTECOLOR]] swap. RGB settings can be changed in colors 0 to 5 and 7 using [[_PALETTECOLOR]].
|
||
|
* '''SCREEN 10''' has '''only 4 color attributes''' with black background. COLOR 0 = black, 1 = grey, 2 = flash white and 3 = bright white.
|
||
|
* '''SCREEN 11''' is '''monochrome''' with white forecolor and a black background.
|
||
|
* '''SCREEN 12''' can use 16 color attributes with a black background. 256K possible RGB color hues. Background colors can be used with QB64.
|
||
|
* '''SCREEN 13''' can use 256 color attributes with a black background. 256K possible RGB hues.
|
||
|
* [[PALETTE]] swaps can be made in SCREEN 7 and 9 only. Those screens were [[DAC]] screen modes in QBasic.
|
||
|
* [[_DEST]] can be used to set the destination page or image to color using '''QB64'''.
|
||
|
* [[_DEFAULTCOLOR]] returns the current color being used on an image or screen page handle.
|
||
|
|
||
|
|
||
|
===24/32-Bit colors using QB64===
|
||
|
* Pixel color intensities for red, green, blue and alpha range from 0 to 255 when used with [[_RGB]], [[_RGBA]], [[_RGB32]] and [[RGBA32]].
|
||
|
* Combined RGB function values returned are [[LONG]] values. '''Blue intensity values may be cut off using [[SINGLE]] variables.'''
|
||
|
* [[_ALPHA]] transparency values can range from 0 as transparent up to 255 which is fully opaque.
|
||
|
* [[_CLEARCOLOR]] can also be used to set a color as transparent.
|
||
|
* Colors can be mixed by using [[_BLEND]] (default) in 32-bit screen modes. [[_DONTBLEND]] disables blending.
|
||
|
* '''NOTE: Default 32-bit backgrounds are clear black or [[_RGBA]](0, 0, 0, 0). Use [[CLS]] to make the black opaque.'''
|
||
|
|
||
|
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p>
|
||
|
|
||
|
==RGB Palette Intensities==
|
||
|
RGB intensity values can be converted to hexadecimal values to create the [[LONG]] [[_PALETTECOLOR]] value in non-32-bit screens:
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 12
|
||
|
alpha$ = "FF" 'solid alpha colors only
|
||
|
{{Cl|PRINT}} "Attribute = Hex value Red Green Blue "
|
||
|
{{Cl|PRINT}}
|
||
|
{{Cl|COLOR}} 7
|
||
|
{{Cl|FOR...NEXT|FOR}} attribute = 1 {{Cl|TO}} 15
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C7, attribute 'set color attribute to read
|
||
|
red$ = {{Cl|HEX$}}({{Cl|INP}}({{Cl|&H}}3C9) * 4) 'convert port setting to 32 bit values
|
||
|
grn$ = {{Cl|HEX$}}({{Cl|INP}}({{Cl|&H}}3C9) * 4)
|
||
|
blu$ = {{Cl|HEX$}}({{Cl|INP}}({{Cl|&H}}3C9) * 4)
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(red$) = 1 {{Cl|THEN}} red$ = "0" + red$ '2 hex digits required
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(grn$) = 1 {{Cl|THEN}} grn$ = "0" + grn$ 'for low or zero hex values
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(blu$) = 1 {{Cl|THEN}} blu$ = "0" + blu$
|
||
|
hex32$ = "{{Cl|&H}}" + alpha$ + red$ + grn$ + blu$
|
||
|
{{Cl|_PALETTECOLOR}} attribute, {{Cl|VAL}}(hex32$) 'VAL converts hex string to a LONG 32 bit value
|
||
|
{{Cl|IF...THEN|IF}} attribute {{Cl|THEN}} {{Cl|COLOR}} attribute 'exclude black color print
|
||
|
{{Cl|PRINT}} "{{Cl|COLOR}}" + {{Cl|STR$}}(attribute) + " = " + hex32$, red$, grn$, blu$ 'returns closest attribute
|
||
|
{{Cl|NEXT}}
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}Attribute Hex value Red Green Blue
|
||
|
|
||
|
{{text|COLOR 1 <nowiki>=</nowiki> &HFF0000A8 00 00 A8|#0050A8}}
|
||
|
{{text|COLOR 2 <nowiki>=</nowiki> &HFF00A800 00 A8 00|#00A800}}
|
||
|
{{text|COLOR 3 <nowiki>=</nowiki> &HFF00A8A8 00 A8 A8|#00A8A8}}
|
||
|
{{text|COLOR 4 <nowiki>=</nowiki> &HFFA80000 A8 00 00|#A80000}}
|
||
|
{{text|COLOR 5 <nowiki>=</nowiki> &HFFA800A8 A8 00 A8|#A800A8}}
|
||
|
{{text|COLOR 6 <nowiki>=</nowiki> &HFFA85400 A8 54 00|#A85400}}
|
||
|
{{text|COLOR 7 <nowiki>=</nowiki> &HFFA8A8A8 A8 A8 A8|#A8A8A8}}
|
||
|
{{text|COLOR 8 <nowiki>=</nowiki> &HFF545454 54 54 54|#545454}}
|
||
|
{{text|COLOR 9 <nowiki>=</nowiki> &HFF5454FC 54 54 FC|#5454FC}}
|
||
|
{{text|COLOR 10 <nowiki>=</nowiki> &HFF54FC54 54 FC 54|#54FC54}}
|
||
|
{{text|COLOR 11 <nowiki>=</nowiki> &HFF5454FC 54 FC FC|#54FCFC}}
|
||
|
{{text|COLOR 12 <nowiki>=</nowiki> &HFFFC5454 FC 54 54|#FC5454}}
|
||
|
{{text|COLOR 13 <nowiki>=</nowiki> &HFFFC54FC FC 54 FC|#FC54FC}}
|
||
|
{{text|COLOR 14 <nowiki>=</nowiki> &HFFFCFC54 FC FC 54|#FCFC54}}
|
||
|
{{text|COLOR 15 <nowiki>=</nowiki> &HFFFCFCFC FC FC FC|#FCFCFC}}
|
||
|
{{OutputEnd}}
|
||
|
:''Explanation:'' The RGB intensity values are multiplied by 4 to get the [[_RGB]] intensity values as [[HEX$|hexadecimal]] values. The individual 2 digit [[HEX$]] intensity values can be added to "&HFF" to make up the 32-bit hexadecimal string value necessary for [[VAL]] to return to [[_PALETTECOLOR]]. The statement is only included in the example to show how that can be done with any 32-bit color value.
|
||
|
|
||
|
|
||
|
===Read & write color port intensities with [[INP]] & [[OUT]]===
|
||
|
* Legacy code may use [[INP]] and [[OUT]] to read or set color port intensities. '''QB64''' emulates VGA memory to maintain compatibility.
|
||
|
* The same can be achieved using [[_PALETTECOLOR]] ('''recommended practice''').
|
||
|
|
||
|
:'''{{text|OUT &H3C7, attribute|green}}''' 'Set port to read RGB settings with:
|
||
|
:'''{{text|color_intensity <nowiki>=</nowiki> INP(&H3C9)|green}}''' 'reads present intensity setting
|
||
|
|
||
|
:'''{{text|OUT &H3C8, attribute|green}}''' 'Set port to write RGB settings with:
|
||
|
:'''{{text|OUT &H3C9, color_intensity|green}}''' 'writes new intensity setting
|
||
|
|
||
|
* After every 3 reads or writes, changes to next higher color attribute. Loops can be used to set more than one attribute's intensities.
|
||
|
* Color port setting of red, green and blue intensities can be done in ascending order.
|
||
|
* Color port attribute intensity values range from 0 to 63 (1/4 of the 32-bit values) in QBasic's legacy 4 and 8 bit screen modes.
|
||
|
|
||
|
<p style="text-align: center">([[#toc|Return to Table of Contents]])</p>
|
||
|
|
||
|
|
||
|
{{PageExamples}}
|
||
|
''Example 1:'' Reading the default RGB color settings of color attribute 15.
|
||
|
{{CodeStart}}
|
||
|
{{Cl|OUT}} &H3C7, 15
|
||
|
red% = {{Cl|INP}}(&H3C9)
|
||
|
green% = {{Cl|INP}}(&H3C9)
|
||
|
blue% = {{Cl|INP}}(&H3C9)
|
||
|
{{Cl|PRINT}} red%, green%, blue%
|
||
|
{{CodeEnd}}
|
||
|
|
||
|
{{OutputStart}}
|
||
|
63 63 63
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 2:'' Changing the color settings of attribute 0 (the background) to blue in [[SCREEN]]s 12 or 13.
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 12
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C8, 0 'set color port attribute to write
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C9, 0 'red intensity
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C9, 0 'green intensity
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C9, 42 'blue intensity
|
||
|
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C7, 0
|
||
|
{{Cl|PRINT}} {{Cl|INP}}({{Cl|&H}}3C9); {{Cl|INP}}({{Cl|&H}}3C9); {{Cl|INP}}({{Cl|&H}}3C9)
|
||
|
{{Cl|END}}
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStartBG1}} 0 0 42 {{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 3:'' Printing in fullscreen SCREEN 0 mode with a color background under the text only.
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 0: {{Cl|_FULLSCREEN}} ' used for fullscreen instead of window
|
||
|
{{Cl|COLOR}} 14, 6: {{Cl|LOCATE}} 4, 4: {{Cl|PRINT}} "Hello!"
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}
|
||
|
|
||
|
|
||
|
{{Ot|Hello!|#fcfc54|#aa5500}}
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 4:'' Using [[CLS]] after setting the background color in SCREEN 0 to make the color cover the entire screen.
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 0: {{Cl|_FULLSCREEN}}
|
||
|
{{Cl|COLOR}} , 7: {{Cl|CLS}}
|
||
|
{{Cl|COLOR}} 9: {{Cl|PRINT}} "Hello"
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStartBG7}}
|
||
|
{{Text|Hello|#5454fc}}
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 5:'' Using a different foreground color for each letter:
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 0
|
||
|
{{Cl|COLOR}} 1: {{Cl|PRINT}} "H";
|
||
|
{{Cl|COLOR}} 3: {{Cl|PRINT}} "E";
|
||
|
{{Cl|COLOR}} 4: {{Cl|PRINT}} "L";
|
||
|
{{Cl|COLOR}} 5: {{Cl|PRINT}} "L";
|
||
|
{{Cl|COLOR}} 6: {{Cl|PRINT}} "O"
|
||
|
{{Cl|COLOR}} 9: {{Cl|PRINT}} "W";
|
||
|
{{Cl|COLOR}} 11: {{Cl|PRINT}} "O";
|
||
|
{{Cl|COLOR}} 12: {{Cl|PRINT}} "R";
|
||
|
{{Cl|COLOR}} 13: {{Cl|PRINT}} "L";
|
||
|
{{Cl|COLOR}} 14: {{Cl|PRINT}} "D"
|
||
|
{{CodeEnd}}
|
||
|
|
||
|
{{OutputStart}}
|
||
|
{{text|H|#0000aa}}{{text|E|#00aaaa}}{{text|L|#aa0000}}{{text|L|#aa00aa}}{{text|O|#aa5500}}
|
||
|
{{text|W|#5454fc}}{{text|O|#54fcfc}}{{text|R|#fc5454}}{{text|L|#fc54fc}}{{text|D|#fcfc54}}
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
{{PageSeeAlso}}
|
||
|
* [[$COLOR]] (metacommand)
|
||
|
* [[_RGB]], [[_RGBA]], [[_RGB32]], [[RGBA32]].
|
||
|
* [[_RED]], [[_GREEN]], [[_BLUE]]
|
||
|
* [[_RED32]], [[_GREEN32]], [[_BLUE32]]
|
||
|
* [[_ALPHA]], [[_ALPHA32]], [[_CLEARCOLOR]]
|
||
|
* [[PRINT]], [[LOCATE]], [[SCREEN]]
|
||
|
* [[POINT]], [[SCREEN (function)]]
|
||
|
* [[OUT]], [[INP]], [[PALETTE]]
|
||
|
* [[_BLINK]]
|
||
|
* [[_DEFAULTCOLOR]]
|
||
|
* [[_BACKGROUNDCOLOR]]
|
||
|
* [[_PALETTECOLOR]]
|
||
|
* [[Windows_Libraries#Color_Dialog_Box|Color Dialog Box]]
|
||
|
* [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values]
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|
||
|
|