自定义颜色#
介绍#
color 类用于在 IQ(第一代)大脑中定义和修改颜色。颜色可以使用 RGB 值、十六进制颜色代码、HSV 值或预定义的颜色常量来创建。
类构造函数#
1 — 创建一个没有指定颜色的
color对象。color();
2 — 根据十六进制或整数值创建一个
color对象。color( int value );
3 — 根据 RGB 值创建
color对象。color( uint8_t r, uint8_t g, uint8_t b );
类析构函数#
销毁 color 对象并释放相关资源。
~color();
参数#
范围 |
类型 |
描述 |
|---|---|---|
|
|
颜色值可以是十六进制 RGB 整数(例如, |
|
|
一个介于 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);
成员功能#
color 类包含以下成员函数:
在调用任何 color 成员函数之前,必须先创建一个 color 实例,如下所示:
// Create a color using RGB values
color brainColor = color(255, 128, 0);
rgb#
使用 RGB 值更新现有 color 对象的颜色。
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 之间的整数,表示颜色中的蓝色分量。 |
返回一个 uint32_t ,表示更新颜色的打包 RGB 值。
// Drive until a teal object is found
color brainColor = color(50, 200, 180);
Drivetrain.drive(forward);
while (true) {
if (Color1.detects(brainColor)) {
Drivetrain.stop();
break;
}
wait(0.5, seconds);
}
hsv#
使用色调、饱和度和亮度值更新现有 color 对象的颜色。
color& hsv(
uint32_t hue,
double sat,
double value );
范围 |
类型 |
描述 |
|---|---|---|
|
|
一个介于 0 到 360 之间的整数,表示颜色的色调。 |
|
|
一个介于 0.0 到 1.0 之间的双精度浮点数,表示颜色的饱和度。 |
|
|
一个介于 0.0 到 1.0 之间的双精度浮点数,表示颜色的亮度。 |
返回对已更新的 color 对象的引用。
// Create a custom teal color
color brainColor = color(50, 200, 180);
// Change the color to magenta
brainColor.hsv(300, 0.75, 0.78);
// Drive forward until a magenta object is found
Drivetrain.drive(forward);
while (true) {
if (Color1.detects(brainColor)) {
Drivetrain.stop();
break;
}
wait(0.5, seconds);
}
web#
使用十六进制或网页颜色值更新现有 color 对象的颜色。
color& web(
const char* color );
范围 |
类型 |
描述 |
|---|---|---|
|
|
定义特定颜色的十六进制或网页颜色值(例如, |
返回对已更新的 color 对象的引用。
// Create a custom teal color
color brainColor = color(50, 200, 180);
// Change the color to magenta
brainColor.web("#AA2896");
// Drive forward until a magenta object is found
Drivetrain.drive(forward);
while (true) {
if (Color1.detects(brainColor)) {
Drivetrain.stop();
break;
}
wait(0.5, seconds);
}