Custom Colors#
Introduction#
VEX V5 supports the use of custom colors for drawing and text. Custom colors can be created using RGB values, hex codes, HSV values, or predefined constants. The color class includes methods for both creating and updating color objects.
Below is a list of available methods:
Constructors — Create a new color object.
color(value)— Accepts a hex integer (e.g.0xFFF700).color(r, g, b)— Creates a color using red, green, and blue values.color(predefinedColor)— Creates a color using a pre-defined color.
Mutators — Update an existing color object.
rgb— Updates a color using new RGB values.hsv— Updates a color using hue, saturation, and brightness.web— Updates a color using a web hex color string (e.g.“#32C8B6”).
Getters — Retrieve information from a color object.
isTransparent— Returns whether the color is transparent.
Constructors#
To use a custom color, you must first create a color object using one of the following constructors:
Hexadecimal Integer#
Creates a color using a six-digit hexadecimal integer.
Usage:
color(value)
Parameter |
Description |
|---|---|
|
A six-digit integer in hexadecimal format (e.g., |
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Create the color yellow using a hexadecimal value
color myYellow = color(0xFFF700);
Brain.Screen.setPenColor(myYellow);
Brain.Screen.print("My Yellow");
}
RGB Constructor#
Creates a color using separate red, green, and blue values.
Usage:
color(r, g, b)
Parameter |
Description |
|---|---|
|
An integer from 0 to 255 representing the red component. |
|
An integer from 0 to 255 representing the green component. |
|
An integer from 0 to 255 representing the blue component. |
// Create the color yellow using RGB values
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Construct a yellow color "Yellow" using a
// RGB values
color myYellow = color(255, 247, 0);
Brain.Screen.setPenColor(myYellow);
Brain.Screen.print("My Yellow");
}
Predefined Color#
Creates a color using a predefined color constant.
Usage:
color(value)
Parameter |
Description |
|---|---|
|
A built-in color constant:
|
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Create the color yellow using a predefined color constant
color myYellow = color(yellow);
Brain.Screen.setPenColor(myYellow);
Brain.Screen.print("My Yellow");
}
Mutators#
These mutators allow you to modify or query a color object after it has been created.
rgb#
rgb updates the color of an existing color object using RGB values.
Usage:
rgb(r, g, b)
Parameters |
Description |
|---|---|
|
An integer from 0 to 255 representing the red component of the color. |
|
An integer from 0 to 255 representing the green component of the color. |
|
An integer from 0 to 255 representing the blue component of the color. |
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);
// Change the color to magenta for a second rectangle
brainColor.rgb(170, 40, 150);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);
}
hsv#
hsv changes an existing color object using HSV values.
Usage:
hsv(h, s, v)
Parameters |
Description |
|---|---|
|
An integer from 0 to 360 representing the hue of the color. |
|
A double from 0.0 to 1.0 representing the saturation of the color. |
|
A double from 0.0 to 1.0 representing the brightness of the color. |
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);
// Change the color to magenta for a second rectangle
brainColor.hsv(300, 0.75, 0.78);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);
}
web#
web changes an existing color object using a web color (hex code).
Usage:
web(value)
Parameters |
Description |
|---|---|
|
A web color (hex code) as a string used to update an existing color object. |
int main() {
vexcodeInit();
// Initializing Robot Configuration. DO NOT REMOVE!
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);
// Change the color to magenta for a second rectangle
brainColor.web("#AA2896");
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);
}
Getters#
isTransparent#
isTransparent returns whether the color is transparent or not.
true— The color is transparent.false— The color is not transparent.
Usage:
isTransparent()
Parameters |
Description |
|---|---|
This method has no parameters. |