自定义颜色#
介绍#
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.
类构造函数#
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 );
类析构函数#
Destroys the color object and releases associated resources.
~color();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
The color value, which can be either a hexadecimal RGB integer (for example, |
|
|
一个介于 0 到 255 之间的整数,表示红色分量。 |
|
|
一个介于 0 到 255 之间的整数,表示绿色分量。 |
|
|
一个介于 0 到 255 之间的整数,表示蓝色分量。 |
笔记#
The following predefined color constants are supported:
blackblueblue_greenblue_violetcyangreenorangepurpleredred_orangered_violettransparentvioletwhiteyellowyellow_greenyellow_orange
例子#
// 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);
成员功能#
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 — 使用打包的 RGB 值更新颜色对象。
uint32_t rgb( uint32_t value );
Parameters2 — 使用单独的 RGB 值更新颜色对象。
uint32_t rgb( uint8_t r, uint8_t g, uint8_t b );
范围 |
类型 |
描述 |
|---|---|---|
|
|
包含所有三个颜色分量的打包 RGB 值。 |
|
|
一个介于 0 到 255 之间的整数,表示颜色中的红色分量。 |
|
|
一个介于 0 到 255 之间的整数,表示颜色中的绿色分量。 |
|
|
一个介于 0 到 255 之间的整数,表示颜色中的蓝色分量。 |
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 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
一个介于 0 到 360 之间的整数,表示颜色的色调。 |
|
|
一个介于 0.0 到 1.0 之间的双精度浮点数,表示颜色的饱和度。 |
|
|
一个介于 0.0 到 1.0 之间的双精度浮点数,表示颜色的亮度。 |
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 );
范围 |
类型 |
描述 |
|---|---|---|
|
|
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);