RGB
ColourValue = RGB(Red, Green, Blue)
 
Parameters:

    Red = The Amount of RED in this colour. (0 to 255)
    Green = The Amount of GREEN in this colour. (0 to 255)
    Blue = The Amount of BLUE in this colour. (0 to 255)
Returns:

    ColourValue = The RGB's levels mixed into a packed RGB colour value
 

      The RGB Function takes the three 8bit colour channel components (R)ed, (G)reen) and (B)lue and blends them together into a single colour value. These colour values can be used to set ink colour of text or other graphics operations.


      You can think of RGB as way of mixing the three components together. Where each Red,Green or Blue component has a valid ranging from zero to 255. Where Zero represents that this channelt is not present and 255 means this component is fully present (bright). We create colours by bending the three levels together.


      Examples:


RED = RGB(255,0,0)
GREEN = RGB(0,255,0)
BLUE = RGB(0,0,255)
PURPLE = RGB(255,0,255)
BLACK = RGB(0,0,0)





FACTS:


      * RGB colour level values are packed together into a single 32bit integer in the following hexadecimal form $--RRGGBB. Throughout the examples you'll most likely find programs that use both methods, and even some that use decimal values. For example, the following statements are all functionally identical. They're all passing the CLS command the a bright blue colour.

  
  Cls 255
  Cls $ff
  Cls RGB(0,0,255)
  


      * The values the RGB command returns are just integer numbers. So if you remember a particular colour value, you can use the value directly when setting the colour of a graphics operation. It's common to use hex$ numbers when doing this, as each pair of HEX digits represents a channel. Literals

      * If you wish to return the A, R, G, or B values from a colour value, use the RGBR, RGBG & RGBB functions.

      * RGB returns a 32bit colour with the alpha channel bits set to zero. If you need those, use the ARGB() function instead.




Mini Tutorial #1:


      This example creates a bunch of Named constants we could use as a list of colours. Therefore each constant is assigned an RGB()colour value.

  
; Make a set of constants for some RGB colours
  Constant BrightRedColour   =RGB(255,0,0)
  Constant BrightGreenColour =RGB(0,255,0)
  Constant DarkBlueColour    =RGB(0,0,255)
  Constant WhiteColour           =RGB(255,255,255)
  Constant BlackColour           =RGB(0,0,0)
  Constant PurpleColour      =RGB(200,0,220)
  
  
; Set the ink colour to our RED colour constant
; then draw some text in the this colour
  
  Ink BrightRedColour
  Print "This Line is drawn in RED"
  Print "Colour Value:"+Str$(BrightRedColour)
  
; Set the ink colour to our GREEN colour constant
; then draw some text in the this colour
  
  Ink BrightGreenColour
  Print "This Line is drawn in GREEN"
  Print "Colour Value:"+Str$(BrightGreenColour)
  
; Set the ink colour to our BLUR colour constant
; then draw some text in the this colour
  
  Ink DarkBlueColour
  Print "This Line is drawn in DARK BLUE"
  Print "Colour Value:"+Str$(DarkBlueColour)
  
; Set the ink colour to our WHITE colour constant
; then draw some text in the this colour
  
  Ink WhiteColour
  Print "This Line is drawn in WHITE"
  Print "Colour Value:"+Str$(WhiteColour)
  
; Show the screen and wait for a key press.
  Sync
  WaitKey
  




This example would output.

  
  This Line is drawn in RED
  Colour Value:16711680
  This Line is drawn in GREEN
  Colour Value:65280
  This Line is drawn in DARK BLUE
  Colour Value:255
  This Line is drawn in WHITE
  Colour Value:16777215
  








Mini Tutorial #2: Emulating RGB function


      This examples shows how the RGB function megres the Red,Green & Blue leveles through into a single integer.


  
  // Compute the Packed RGB value
  ThisColour=CustomRGB(80,160,255)
  
  // display the lkevels of RED , GREEN and BLUE
  // in this packed colour
  Print RgbR(ThisCOlour)
  Print RgbG(ThisCOlour)
  Print RgbB(ThisCOlour)
  
  
; Show the screen and wait for a key press.
  Sync
  WaitKey
  
  
  
  
  
  
  
  
Function CustomRGB(Red,Green,Blue)
  
  // Mask the RED level and shift it into position
  PackedColour      = (  Red & 255)<<16
  
  // Mask and shift the Green level or it with the RED
  PackedColour     |= (Green & 255)<<8
  
  // Mask and shift the Blue level or it with the RED+Green
  PackedColour     |= (Blue  & 255)
  
EndFunction PackedColour
  
  
; Show the screen and wait for a key press.
  Sync
  WaitKey
  




This example would output.

  
  80
  160
  255
  





 
Related Info: ARGB | Literals | RGBA | RGBB | RGBFade | RGBG | RGBR | RndRGB :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com