Returns a single color value from a set of red, green, and blue color components.
x% = _RGB( r, g, b)
x% : iexp
r, g, b : iexp
Specifies the intensity of the red, green, and blue color components. The values can range from 0 to 255. Zero is the minimum color intensity; 255 is the maximum color intensity.
_RGB() clips the passed values to the range 0 .. 255. Wrong values are corrected automatically. For instance, the value 257 is set to 255, and for negative values the color value is rounded to zero.
OpenW 1
Local a%, col%
Line 10, 10, 10, 150
Auto
col% = _RGB(150, 150, 150)
Color col%
Circle 30, 30, 100
col% = _RGB(-3, 510, -10)
Color col%
Circle 100, 100, 150
KeyGet a
CloseW 1
_RGB(250 + 20, 100 + 20, 80 + 20) results in RGB(255, 120, 100), not RGB(14, 120, 100) [14 == (270 And 255)]. _RGB is implemented as an optimized library function; it is not in-lined due to its complexity. As an illustration, the following code is required (more or less):
Function RGBAdd(ByVal Rgb1 As Int, ByVal hue As Int) As Int
Dim tR As Int, tG As Int, tB As Int
tR = GetRValue(Rgb1) + hue
tG = GetGValue(Rgb1) + hue
tB = GetBValue(Rgb1) + hue
If tR > 255 Then tR = 255
If tG > 255 Then tG = 255
If tB > 255 Then tB = 255
If tR < 0 Then tR = 0
If tG < 0 Then tG = 0
If tB < 0 Then tB = 0
Return RGB(tR, tG, tB)
EndFunction
GFA-BASIC 32 brings it back to:
Function RGBAdd2(ByVal Rgb1 As Int, ByVal hue As Int) As Int
Return _RGB(GetRValue(Rgb1) + hue, GetGValue(Rgb1) + hue, GetBValue(Rgb1) + hue)
EndFunction
By incrementing the r-g-b values using _RGB will eventually result in white (255,255,255).
The other function to create a RGB colour value RGB() is a bit faster, but doesn't perform overflow checking. For instance, the value 256 is converted to 1. Incrementing the colors using RGB() does not result in the end color white.
{Created by Sjouke Hamstra; Last updated: 23/09/2014 by James Gaite}