Custom Colors#
Introduction#
VEX IQ (2nd gen) 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 (0–255).
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 (0–360), saturation, and brightness (0.0–1.0).
web() – Updates a color using a web hex color string (e.g.
"#32C8B6"
).
Getters
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., |
// Construct a yellow 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. |
// Construct a yellow color "Yellow" using
// 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:
|
// Construct a yellow color "Yellow" using a
// predefined color constant
color Yellow = color(yellow);
Brain.Screen.setPenColor(Yellow);
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. |
// Create a custom teal color and set it as the pen color
color brainColor = color(50, 200, 180);
Brain.Screen.setPenColor(brainColor);
// Draw a rectangle with the teal outline
Brain.Screen.drawRectangle(5, 10, 80, 40);
// Draw another rectangle with a magenta outline
brainColor.rgb(170, 40, 150);
Brain.Screen.setPenColor(brainColor);
Brain.Screen.drawRectangle(5, 60, 80, 40);
hsv#
hsv(hue, saturation, value)
changes the existing color instance 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. |
Returns: An integer value representing the color.
// Create a custom teal color and set it as the pen color
color brainColor = color(50, 200, 180);
Brain.Screen.setPenColor(brainColor);
// Draw a rectangle with the teal outline
Brain.Screen.drawRectangle(5, 10, 80, 40);
// Draw another rectangle with a magenta outline
brainColor.hsv(300, 0.75, 0.78);
Brain.Screen.setPenColor(brainColor);
Brain.Screen.drawRectangle(5, 60, 80, 40);
web#
web(value)
changes the existing color instance using a web color (hex code).
Usage:
web(value)
Parameters |
Description |
---|---|
|
A web color (hex code) as a string used to update the existing color instance. |
Returns: An integer value representing the color.
// Create a custom teal color and set it as the pen color
color brainColor = color();
brainColor.web("#32C8B6");
Brain.Screen.setPenColor(brainColor);
// Draw a rectangle with the teal outline
Brain.Screen.drawRectangle(5, 10, 80, 40);
// Draw another rectangle with the new magenta outline
brainColor.web("#AA2896");
Brain.Screen.setPenColor(brainColor);
Brain.Screen.drawRectangle(5, 60, 80, 40);
Getters#
isTransparent#
isTransparent()
returns whether the color is transparent or not.
true
- The color is transparent.false
- The color is not transparent.
Usage:
isTransparent()
// Create a transparent color
color transparentColor = color(transparent);
// Check if the color is transparent
if (transparentColor.isTransparent()) {
Brain.Screen.print("Transparent");
} else {
Brain.Screen.print("Not transparent");
}