Colores personalizados#
Introducción#
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.
A continuación se muestra una lista de los métodos disponibles:
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.
Constructores#
To use a custom color, you must first create a color object using one of the following constructors:
Hexadecimal Integer#
Crea un color utilizando un entero hexadecimal de seis dígitos.
Usage:
color(value)
Parámetro |
Descripción |
|---|---|
|
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#
Crea un color utilizando valores separados de rojo, verde y azul.
Usage:
color(r, g, b)
Parámetro |
Descripción |
|---|---|
|
Un número entero de 0 a 255 que representa el componente rojo. |
|
Un número entero de 0 a 255 que representa el componente verde. |
|
Un número entero de 0 a 255 que representa el componente azul. |
// 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#
Crea un color utilizando una constante de color predefinida.
Usage:
color(value)
Parámetro |
Descripción |
|---|---|
|
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");
}
Mutadores#
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)
Parámetros |
Descripción |
|---|---|
|
Un número entero de 0 a 255 que representa el componente rojo del color. |
|
Un número entero de 0 a 255 que representa el componente verde del color. |
|
Un número entero de 0 a 255 que representa el componente azul del 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)
Parámetros |
Descripción |
|---|---|
|
Un número entero de 0 a 360 que representa el tono del color. |
|
Un doble de 0,0 a 1,0 que representa la saturación del color. |
|
Un doble de 0,0 a 1,0 que representa el brillo del 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)
Parámetros |
Descripción |
|---|---|
|
Un color web (código hexadecimal) como una cadena utilizada para actualizar un objeto de color existente. |
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);
}
Captadores#
isTransparent#
isTransparent returns whether the color is transparent or not.
true— The color is transparent.false— The color is not transparent.
Usage:
isTransparent()
Parámetros |
Descripción |
|---|---|
Este método no tiene parámetros. |