mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-22 05:35:08 +00:00
66 lines
3.7 KiB
Text
66 lines
3.7 KiB
Text
{{DISPLAYTITLE:_RGB}}
|
|
The [[_RGB]] function returns the closest palette attribute index (legacy SCREEN modes) OR the [[LONG]] 32-bit color value (32-bit screens).
|
|
|
|
|
|
{{PageSyntax}}
|
|
: {{Parameter|colorIndex~&}} = [[_RGB]]({{Parameter|red&}}, {{Parameter|green&}}, {{Parameter|blue&}}[, {{Parameter|imageHandle&}}])
|
|
|
|
|
|
{{PageDescription}}
|
|
* The value returned is either the closest color attribute number or a 32-bit [[_UNSIGNED]] [[LONG]] color value.
|
|
* '''Return variable types must be [[LONG]] or resulting color may lose the [[_BLUE]] value.'''
|
|
* {{Parameter|red&}} specifies the red component intensity from 0 to 255.
|
|
* {{Parameter|green&}} specifies the green component intensity from 0 to 255.
|
|
* {{Parameter|blue&}} specifies the blue component intensity from 0 to 255.
|
|
* Intensity values outside the valid range are clipped.
|
|
* Returns [[LONG]] 32-bit hexadecimal values from '''&HFF{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}''', always with full [[_ALPHA]].
|
|
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|colorIndex~&}}), 3) to place 3 colors.
|
|
* If the {{Parameter|imageHandle&}} is omitted the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page.
|
|
* Colors returned are always opaque as the transparency value is always 255. Use [[_ALPHA]] or [[_CLEARCOLOR]] to change it.
|
|
* '''NOTE: Default 32-bit backgrounds are clear black or [[_RGBA]](0, 0, 0, 0). Use [[CLS]] to make the black opaque.'''
|
|
|
|
|
|
{{PageExamples}}
|
|
''Example:'' Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values.
|
|
{{CodeStart}}
|
|
{{Cl|SCREEN}} 12
|
|
{{Cl|DIM}} hex32$(15)
|
|
{{Cl|FOR...NEXT|FOR}} attribute = 1 {{Cl|TO}} 15
|
|
{{Cl|OUT}} {{Cl|&H}}3C7, attribute 'set color attribute to read
|
|
red = {{Cl|INP}}({{Cl|&H}}3C9) * 4 'multiply by 4 to convert intensity to 0 to 255 RGB values
|
|
grn = {{Cl|INP}}({{Cl|&H}}3C9) * 4
|
|
blu = {{Cl|INP}}({{Cl|&H}}3C9) * 4
|
|
hex32$(attribute) = "{{Cl|&H}}" + {{Cl|HEX$}}({{Cl|_RGB32}}(red, grn, blu)) 'always returns the 32 bit value
|
|
{{Cl|COLOR}} attribute
|
|
{{Cl|PRINT}} "{{Cl|COLOR}}" + {{Cl|STR$}}({{Cl|_RGB}}(red, grn, blu)) + " = " + hex32$(attribute) 'closest attribute
|
|
{{Cl|NEXT}} '' ''
|
|
{{CodeEnd}}
|
|
{{OutputStart}}{{text|COLOR 1 <nowiki>=</nowiki> &HFF0000A8|#0000A8}}
|
|
{{text|COLOR 2 <nowiki>=</nowiki> &HFF00A800|#00A800}}
|
|
{{text|COLOR 3 <nowiki>=</nowiki> &HFF00A8A8|#00A8A8}}
|
|
{{text|COLOR 4 <nowiki>=</nowiki> &HFFA80000|#A80000}}
|
|
{{text|COLOR 5 <nowiki>=</nowiki> &HFFA800A8|#A800A8}}
|
|
{{text|COLOR 6 <nowiki>=</nowiki> &HFFA85400|#A85400}}
|
|
{{text|COLOR 7 <nowiki>=</nowiki> &HFFA8A8A8|#A8A8A8}}
|
|
{{text|COLOR 8 <nowiki>=</nowiki> &HFF545454|#545454}}
|
|
{{text|COLOR 9 <nowiki>=</nowiki> &HFF5454FC|#5454FC}}
|
|
{{text|COLOR 10 <nowiki>=</nowiki> &HFF54FC54|#54FC54}}
|
|
{{text|COLOR 11 <nowiki>=</nowiki> &HFF54FCFC|#54FCFC}}
|
|
{{text|COLOR 12 <nowiki>=</nowiki> &HFFFC5454|#FC5454}}
|
|
{{text|COLOR 13 <nowiki>=</nowiki> &HFFFC54FC|#FC54FC}}
|
|
{{text|COLOR 14 <nowiki>=</nowiki> &HFFFCFC54|#FCFC54}}
|
|
{{text|COLOR 15 <nowiki>=</nowiki> &HFFFCFCFC|#FCFCFC}}
|
|
{{OutputEnd}}
|
|
:''Note:'' This procedure also shows how the returns from [[_RGB]] and [[_RGB32]] differ in a non-32 bit screen mode.
|
|
|
|
|
|
{{PageSeeAlso}}
|
|
* [[_RGBA]], [[_RGB32]], [[_RGBA32]]
|
|
* [[_RED]], [[_GREEN]], [[_BLUE]]
|
|
* [[_LOADIMAGE]], [[_NEWIMAGE]]
|
|
* [[HEX$ 32 Bit Values]], [[POINT]]
|
|
* [[SAVEIMAGE]]
|
|
* [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values]
|
|
|
|
|
|
{{PageNavigation}}
|