Colors
In BBj 20.10 and higher, Colors
is a BBj Custom Class that provides commonly-used routines to convert
and format colors in a variety of models including Java Color, BBjColor, and RGB, HSL, HSB, and hexadecimal representation.
Note that most of the methods are static, meaning that you don't have to instantiate a custom object in order to use the class.
For example:
myBBjColor! = Colors.getBBjColorFromHexString("#fafbfc")
Most color representations support a built-in alpha channel and the conversion will take that into account. For backward compatibility
with older systems, hex color strings and formatted HSLA strings are returned without the alpha digits when the alpha channel is fully opaque.
There are a variety of ways to specify a hexadecimal color, including standard and shorthand notation, with or without an octothorpe (#), and with or without an alpha component:
#rrggbb
- standard representation, prefixed by an octothorpe (the pound sign) with two hex digits for the red, green, and blue (RGB) channels
rrggbb
- standard representation without the octothorpe with two hex digits for the RGB channels
#rgb
- shorthand representation with 1 hexadecimal digit that will be doubled for the RGB channels, e.g. #f0c = #ff00cc
rgb
- shorthand representation without the octothorpe with 1 hexadecimal digit that will be doubled for the RGB channels, e.g. #f0c = #ff00cc
#rrggbbaa
- standard representation with two hex digits for the red, green, blue, and alpha (RGBA) channels
rrggbbaa
- standard representation without the octothorpe with two hex digits for the RGBA channels
#rgba
- shorthand representation with 1 hexadecimal digit that will be doubled for the RGBA channels, e.g. #f0c8 = #ff00cc88
rgba
- shorthand representation without the octothorpe with 1 hexadecimal digit that will be doubled for the RGBA channels, e.g. #f0c8 = #ff00cc88
For all Hue, Saturation, Lightness, and Alpha methods, all parameters are floating point number with the following numerical ranges:
- The hue component of the color is a floating point number from 0-360 indicating the hue degree in the color circle (0=red, 120=green, 240=blue, 360=red)
- The saturation component of the color is a floating point number from 0-1 indicating the saturation percentage (0=grey or no color, 1=full color)
- The lightness component of the color is a floating point number from 0-1 indicating the lightness percentage (0=black, 1 = white)
- The alpha component of the color is a floating point number from 0-1 indicating the alpha percentage (0=transparent, 1=opaque)
For all Hue, Saturation, Brightness, and Alpha methods, all parameters are floating point number with the following numerical ranges:
- The hue component of the color is a floating point number from 0-360 indicating the hue degree in the color circle (0=red, 120=green, 240=blue, 360=red)
- The saturation component of the color is a floating point number from 0-1 indicating the saturation percentage (0=grey or no color, 1=full color)
- The brightness component of the color is a floating point number from 0-1 indicating the lightness percentage (0=black, 1 = white)
- The alpha component of the color is a floating point number from 0-1 indicating the alpha percentage (0=transparent, 1=opaque)
Comparing HSL and HSB Color Models:
HSB is the same color model as HSV, where the last letter stands for Brightness or Value and resolve to the same value. HSB differs from HSL, even
though we typically think of Lightness and Brightness as the same thing. In the HSL color model the Saturation ranges from grey to full color, and
the Lightness ranges from black (0) to full color (0.5) to white (1). In the HSB color model the Saturation ranges from white to full color, and
the Brightness ranges from black to full color.
THROW
n Error Codes:
313
: Invalid color specified. The specified string for a hex color description was invalid. It should be in a format like #fafbfc
, or #f0c
, or #fafbfc80
, or #f0cc
.
314
: Invalid BBjVector of HSLA or HSBA values provided.
315
: Invalid hex value provided.
316
: Invalid decimal value provided.
ToDo:
color manipulation: darken, lighten, saturate, desaturate
color blending