rgb

Prev Next

Function Names

rgb

Library

Style Library

Description

This function converts a specified color into RGB values in a set.

Call as: function

Restrictions

Don't forget to include 'Style Library' at the top of your program

Parameter count

1

Parameters

No.TypeDescription
1.
reference
set
string
Color

The value must be provided in a variable which will be converted by this function to RGB colo Three possibiltes to specify the color:

  • As RGB in a set containing 3 numbers (0..255). Example: { 255, 128, 64 }. In this case, the values will be verified and, if necessary, corrected.
  • Existing color name. Example: red, blue, navy, ecru
  • Hexadecimal code: '#' followed by 6 hexdecimal digits. Example: #FF8040

Return value

TypeDescription
string Error message

If a blank string is returned, then the conversion is successful, Otherwise, a comprehensible error message will be returned.

Examples

       a[0] = navy;
       a[1] = {0,0,128};
       a[2] = "#000080";
       a[3] = "gnu not a color";

       for all variables( a[], value[], i[] )
       {
           msg[] = rgb( value[] );
           echo(i[], ": ", value[], ",  Message: ", msg[] );
       }

Output

0: {0,0,128},  Message:
1: {0,0,128},  Message:
2: {0,0,128},  Message:
3: gnu not a color,  Message: Specified color name 'gnu not a color' is unknown
Try it yourself: Open LIB_Function_rgb.b4p in B4P_Examples.zip. Decompress before use.

See also

lighten color
darken color
weaken color