Difference between revisions of "HEX$ 32 Bit Values"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
 
(6 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[HEX$|Hexadecimal]] values can be used to set a [[_PALETTECOLOR]] instead of using [[_RGB32]] or [[_RGBA32]] values.
[[LONG]] [[HEX$|Hexadecimal]] values can be used to set a [[_PALETTECOLOR]] instead of using [[_RGB32]] or [[_RGBA32]] values.




The hex value for bright white(attribute 15) is &HFFFFFFFF or:
* 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)
::: [[_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.


[[_RGB]] will return an alpha value of 255 for fully opaque 32 bit colors only. Values can range from &HFF000000 to &HFFFFFFFF.
* [[_RGBA]] can set the transparency so hexadecimal values range from &H000000 (zero alpha) to &HFFFFFFFF (full alpha).


[[_RGB32]] will always return an alpha value of 255 for fully opaque colors only. Values can range from &HFF000000 to &HFFFFFFFF.
* [[_RGBA32]] can set the transparency so hexadecimal values range from &H000000 (zero alpha) to &HFFFFFFFF (full alpha).


[[_RGBA]] can set the transparency so hexadecimal values can 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:


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


:: _PALETTECOLOR 1, '''&HFF{{text|FF|red}}{{text|00|green}}{{text|00|blue}}''' 'COLOR 1 is full red
:Where '''FF''' is the fully opaque [[_ALPHA]] and the 3 hex color values can range from '''00''' to '''FF''' (0 to 255) each.
:: _PALETTECOLOR 2, '''&HFF{{text|FF|red}}{{text|00|green}}{{text|FF|blue}}''' 'COLOR 2 is purple
:: _PALETTECOLOR 3, '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|00|blur}}''' 'COLOR 3 is brown




Line 26: Line 33:
{{Cl|DIM}} hex32$(15)
{{Cl|DIM}} hex32$(15)
alpha$ = "FF"                              'solid alpha colors only
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
{{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|FOR...NEXT|FOR}} attribute = 0 {{Cl|TO}} 15
Line 44: Line 51:
   {{Cl|PRINT}} "COLOR" + {{Cl|STR$}}(i) + " = " + hex32$(i) 'returns closest attribute
   {{Cl|PRINT}} "COLOR" + {{Cl|STR$}}(i) + " = " + hex32$(i) 'returns closest attribute
{{Cl|NEXT}} '' ''
{{Cl|NEXT}} '' ''
{{CodeEnd}}
{{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]].
:''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.
:: No VAL conversion is necessary if the [[LONG]] [[&H]] hexadecimal values are entered into the program directly by the programmer.





Latest revision as of 17:28, 13 February 2021

LONG 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 values up to 255 can represented by two hexadecimal digits such as 1C, 23, FA, etc.
  • The hex value for bright white(attribute 15) is &HFFFFFFFF or:
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 values.

SCREEN 12 DIM hex32$(15) alpha$ = "FF" 'solid alpha colors only OUT &H3C8, 0: OUT &H3C9, 0: OUT &H3C9, 0: OUT &H3C9, 20 'set black background to dark blue FOR attribute = 0 TO 15 OUT &H3C7, attribute 'set color attribute to read red$ = HEX$(INP(&H3C9) * 4) 'convert port setting to 32 bit values grn$ = HEX$(INP(&H3C9) * 4) blu$ = HEX$(INP(&H3C9) * 4) IF LEN(red$) = 1 THEN red$ = "0" + red$ 'necessary for low or zero color intensities IF LEN(grn$) = 1 THEN grn$ = "0" + grn$ IF LEN(blu$) = 1 THEN blu$ = "0" + blu$ hex32$(attribute) = "&H" + alpha$ + red$ + grn$ + blu$ NEXT PRINT "COLOR 0 = " + hex32$(0) FOR i = 1 TO 15 _PALETTECOLOR i, VAL(hex32$(i)) COLOR i PRINT "COLOR" + STR$(i) + " = " + hex32$(i) 'returns closest attribute NEXT

Code by Ted Weissgerber
Explanation: VAL is used to convert the hexadecimal 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:



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page