mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-22 05:35:08 +00:00
67 lines
3.3 KiB
Text
67 lines
3.3 KiB
Text
|
[[LONG]] [[HEX$|Hexadecimal]] values can be used to set a [[_PALETTECOLOR]] instead of using [[_RGB32]] or [[_RGBA32]] values.
|
||
|
|
||
|
|
||
|
* Hexadecimal digits can be represented as any number or letter up to F: '''0 1 2 3 4 5 6 7 8 9 A B C D E F'''
|
||
|
|
||
|
* [[_BYTE|Byte]] values up to 255 can represented by two hexadecimal digits such as 1C, 23, FA, etc.
|
||
|
|
||
|
* The [[HEX$|hex]] value for bright white(attribute 15) is &HFFFFFFFF or:
|
||
|
|
||
|
::: [[_ALPHA|Alpha]] = FF (255), Red = FF (255), Green = FF (255), Blue = FF (255)
|
||
|
|
||
|
* [[_RGB]] will return an alpha value of 255 for fully opaque 32 bit colors only. Values range from &HFF000000 to &HFFFFFFFF.
|
||
|
|
||
|
* [[_RGB32]] will return an alpha value of 255 for fully opaque colors only. Values range from &HFF000000 to &HFFFFFFFF.
|
||
|
|
||
|
* [[_RGBA]] can set the transparency so hexadecimal values range from &H000000 (zero alpha) to &HFFFFFFFF (full alpha).
|
||
|
|
||
|
* [[_RGBA32]] can set the transparency so hexadecimal values range from &H000000 (zero alpha) to &HFFFFFFFF (full alpha).
|
||
|
|
||
|
|
||
|
* So expanding on the principle above allows us to easily make up our own hex color values:
|
||
|
|
||
|
:: _PALETTECOLOR 1, '''&HFFFF0000''' 'COLOR 1 is full red
|
||
|
:: _PALETTECOLOR 2, '''&HFFFF00FF''' 'COLOR 2 is purple
|
||
|
:: _PALETTECOLOR 3, '''&HFFFFFF00''' 'COLOR 3 is brown
|
||
|
|
||
|
:Where '''FF''' is the fully opaque [[_ALPHA]] and the 3 hex color values can range from '''00''' to '''FF''' (0 to 255) each.
|
||
|
|
||
|
|
||
|
''Example:'' Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal [[STRING|string]] values.
|
||
|
{{CodeStart}}
|
||
|
{{Cl|SCREEN}} 12
|
||
|
{{Cl|DIM}} hex32$(15)
|
||
|
alpha$ = "FF" 'solid alpha colors only
|
||
|
{{Cl|OUT}} {{Cl|&H}}3C8, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 0: {{Cl|OUT}} {{Cl|&H}}3C9, 20 'set black background to dark blue
|
||
|
|
||
|
{{Cl|FOR...NEXT|FOR}} attribute = 0 {{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$ 'necessary for low or zero color intensities
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(grn$) = 1 {{Cl|THEN}} grn$ = "0" + grn$
|
||
|
{{Cl|IF...THEN|IF}} {{Cl|LEN}}(blu$) = 1 {{Cl|THEN}} blu$ = "0" + blu$
|
||
|
hex32$(attribute) = "{{Cl|&H}}" + alpha$ + red$ + grn$ + blu$
|
||
|
{{Cl|NEXT}}
|
||
|
{{Cl|PRINT}} "COLOR 0 = " + hex32$(0)
|
||
|
{{Cl|FOR...NEXT|FOR}} i = 1 {{Cl|TO}} 15
|
||
|
{{Cl|_PALETTECOLOR}} i, {{Cl|VAL}}(hex32$(i))
|
||
|
{{Cl|COLOR}} i
|
||
|
{{Cl|PRINT}} "COLOR" + {{Cl|STR$}}(i) + " = " + hex32$(i) 'returns closest attribute
|
||
|
{{Cl|NEXT}} '' ''
|
||
|
{{CodeEnd}}{{small|Code by Ted Weissgerber}}
|
||
|
:''Explanation:'' [[VAL]] is used to convert the [[HEX$|hexadecimal]] [[STRING|string]] values to valid 32 bit color values for [[_PALETTECOLOR]].
|
||
|
:: No VAL conversion is necessary if the [[LONG]] [[&H]] hexadecimal values are entered into the program directly by the programmer.
|
||
|
|
||
|
|
||
|
''See also:''
|
||
|
* [[_PALETTECOLOR]]
|
||
|
* [[_RGB32]], [[_RGBA32]]
|
||
|
* [[_RGB]], [[_RGBA]] {{text|(when used in 32 bit only)}}
|
||
|
* [[COLOR]], [[SCREEN]], [[POINT]]
|
||
|
* [http://www.w3schools.com/html/html_colornames.asp HTML Color Table HEX Values and Names]
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|