Colores personalizados#

Introducción#

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.

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”).

Conseguidores

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

value

A six-digit integer in hexadecimal format (e.g., 0xFFF700 for yellow).

// Construct a yellow 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

r

Un número entero de 0 a 255 que representa el componente rojo.

g

Un número entero de 0 a 255 que representa el componente verde.

b

Un número entero de 0 a 255 que representa el componente azul.

// 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#

Crea un color utilizando una constante de color predefinida.

Usage:
color(value)

Parámetro

Descripción

value

A built-in color constant:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • transparent
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange

// Construct a yellow color "Yellow" using a
// predefined color constant
color Yellow = color(yellow);

Brain.Screen.setPenColor(Yellow);
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

r

Un número entero de 0 a 255 que representa el componente rojo del color.

g

Un número entero de 0 a 255 que representa el componente verde del color.

b

Un número entero de 0 a 255 que representa el componente azul del 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)

Parámetros

Descripción

h

Un número entero de 0 a 360 que representa el tono del color.

s

Un doble de 0,0 a 1,0 que representa la saturación del color.

v

Un doble de 0,0 a 1,0 que representa el brillo del color.

Devuelve: Un valor entero que representa el 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)

Parámetros

Descripción

value

Un color web (código hexadecimal) como una cadena utilizada para actualizar la instancia de color existente.

Devuelve: Un valor entero que representa el 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);

Captadores#

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");
}