Colores personalizados#
Introducción#
The color class is used to define and modify colors for drawing shapes and displaying text on the V5 Brain Screen. Colors can be created using RGB values, hexadecimal color codes, HSV values, or predefined color constants.
Constructores de clases#
1 — Creates a
colorobject with no assigned color.color();
2 — Creates a
colorobject from a hexadecimal or integer value.color( int value );
3 — Creates a
colorobject from RGB values.color( uint8_t r, uint8_t g, uint8_t b );
Instructor de clase#
Destroys the color object and releases associated resources.
~color();
Parámetros#
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
The color value, which can be either a hexadecimal RGB integer (for example, |
|
|
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. |
Notas#
The following predefined color constants are supported:
blackblueblue_greenblue_violetcyangreenorangepurpleredred_orangered_violettransparentvioletwhiteyellowyellow_greenyellow_orange
Ejemplo#
// Create the color yellow using a hexadecimal value
color myYellow = color(0xFFF700);
// Create a color using RGB values
color myBlue = color(0, 100, 255);
// Create a color using a predefined constant
color myRed = color(red);
Funciones de los miembros#
The color class includes the following member functions:
rgb— Updates the color using RGB values.hsv— Updates the color using HSV values.web— Updates the color using a web hex color string.
Before calling any color member functions, a color instance must be created, as shown below:
// Create a color using RGB values
color brainColor = color(255, 128, 0);
rgb#
Updates the color of an existing color object using RGB values.
1 — Actualiza un objeto de color con un valor RGB empaquetado.
uint32_t rgb( uint32_t value );
Parameters2 — Actualiza un objeto de color con valores RGB separados.
uint32_t rgb( uint8_t r, uint8_t g, uint8_t b );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Un valor RGB empaquetado que contiene los tres componentes de color. |
|
|
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. |
Returns a uint32_t representing the packed RGB value of the updated color.
// 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#
Updates the color of an existing color object using hue, saturation, and brightness values.
hsv(
uint32_t hue,
double sat,
double value );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
Un número entero del 0 al 360 que representa el tono del color. |
|
|
Un valor decimal entre 0,0 y 1,0 que representa la saturación del color. |
|
|
Un valor decimal entre 0,0 y 1,0 que representa el brillo del color. |
Returns a reference to the updated color object.
// 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#
Updates the color of an existing color object using a hexadecimal or web color value.
web(
const char* color );
Parámetro |
Tipo |
Descripción |
|---|---|---|
|
|
A hexadecimal or web color value that defines a specific color (e.g., |
Returns a reference to the updated color object.
// 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);