The VCSSL Color library is a standard library for supporting color handling.It is mainly used for graphics-related processing together with libraries such as Graphics2D and Graphics3D.
In this library, a color is represented as an int[4] array. The elements store the red component at [0], green at [1], blue at [2], and alpha at [3].
The range of each component is from 0 to 255. In other words, an int[4] array represents a 32-bit RGBA color.
Consistently with this library, Graphics2D and Graphics3D also treat int[4] arrays as 32-bit RGBA colors, so they can be used for setting and obtaining colors.
As an example, the drawing color in Graphics2D can be set to blue as follows even without using the Color library:
However, by using the Color library, colors can be specified in various forms as shown below:
- None -
| Name | BLACK |
| Declaration | const int BLACK[ ] |
| Description | The array storing the color components of black. |
| Name | WHITE |
| Declaration | const int WHITE[ ] |
| Description | The array storing the color components of white. |
| Name | RED |
| Declaration | const int RED[ ] |
| Description | The array storing the color components of red. |
| Name | GREEN |
| Declaration | const int GREEN[ ] |
| Description | The array storing the color components of green. |
| Name | BLUE |
| Declaration | const int BLUE[ ] |
| Description | The array storing the color components of blue. |
| Name | MAGENTA |
| Declaration | const int MAGENTA[ ] |
| Description | The array storing the color components of purple (magenta). |
| Name | YELLOW |
| Declaration | const int YELLOW[ ] |
| Description | The array storing the color components of yellow. |
| Name | CYAN |
| Declaration | const int CYAN[ ] |
| Description | The array storing the color components of light blue (cyan). |
| Name | color |
| Declaration | int[ ] color(int red, int green, int blue, int alpha) |
| Description | Creates and returns an array storing color components from integer RGBA values in the range from 0 to 255. |
| Parameters |
(int type) red : The red component (0 to 255). (int type) green : The green component (0 to 255). (int type) blue : The blue component (0 to 255). (int type) alpha : The alpha component (0 to 255). |
| Return | (int[] type) The array storing the color components. |
| Name | color |
| Declaration | int[ ] color(int red, int green, int blue) |
| Description | Creates and returns an array storing color components for an opaque color from integer RGB values in the range from 0 to 255. |
| Parameters |
(int type) red : The red component (0 to 255). (int type) green : The green component (0 to 255). (int type) blue : The blue component (0 to 255). |
| Return | (int[] type) The array storing the color components. |
| Name | color |
| Declaration | int[ ] color(float red, float green, float blue, float alpha) |
| Description | Creates and returns an array storing color components from floating-point RGBA values in the range from 0.0 to 1.0. |
| Parameters |
(float type) red : The red component (0.0 to 1.0). (float type) green : The green component (0.0 to 1.0). (float type) blue : The blue component (0.0 to 1.0). (float type) alpha : The alpha component (0.0 to 1.0). |
| Return | (int[] type) The array storing the color components. |
| Name | color |
| Declaration | int[ ] color(float red, float green, float blue) |
| Description | Creates and returns an array storing color components for an opaque color from floating-point RGB values in the range from 0.0 to 1.0. |
| Parameters |
(float type) red : The red component (0.0 to 1.0). (float type) green : The green component (0.0 to 1.0). (float type) blue : The blue component (0.0 to 1.0). |
| Return | (int[] type) The array storing the color components. |
| Name | color |
| Declaration | int[ ] color(int hexCode) |
| Description |
Creates and returns an array storing color components for an opaque color from a hexadecimal color code. For example, to convert the blue color code 0000ff: int rgba[] = color(0x0000ff); Here, 0x is the prefix used to write an integer literal in hexadecimal notation. |
| Parameters | (int type) hexCode : The hexadecimal color code. |
| Return | (int[] type) The array storing the color components. |
| Name | getColorCode |
| Declaration | int getColorCode(int rgba[ ]) |
| Description |
Converts an array of color components into a color code and returns it.For example, to convert purple (magenta) into a color code: int rgba[] = { 255, 0, 255, 255 }; int colorCode = getColorCode(rgba); string hexCode = hex(colorCode); The result stored in the variable hexCode is 0xff00ff. For green, the result is 0xff00, and for blue, it is 0xff. To format it into a more common color-code style, remove the leading 0x and pad it with zeros on the left so that it has six digits. The Text library is useful for such string processing. |
| Parameters | rgba[] : The array storing the color components. [0] is the red component, [1] is the green component, [2] is the blue component, and [3] is the alpha component. Each color component must be in the range from 0 to 255, and the alpha component must always be 255 (opaque). |
| Return | (int type) The integer color-code value. To convert it into a hexadecimal string, use the hex function. |