自定义颜色#

介绍#

VEX AIR 无人机支持使用自定义颜色绘制和打印文本。自定义颜色可以使用 RGB 值或十六进制代码创建。自定义颜色还包含在项目期间更新颜色对象的方法。

以下是可用构造函数的列表:

Constructors – Create a new Color object.

  • Color(value) – Creates a color using a hex string (e.g. "#FFF700") or hex integer (e.g. 0xFFF700).

  • Color(r, g, b) – Creates a color using red, green, and blue values.

Mutators – 更新现有的“Color”对象。

  • rgb – Sets a created color object to a new color using RGB values.

  • hsv – Sets a created color object to a new color using hue, saturation, and brightness values.

  • web – Sets a created color object to a new color using a web hex color string (e.g. "#32C8B6").

Getters – 返回颜色对象的色调或饱和度值。

  • saturation – Returns the saturation value for a custom color.

  • hue – Returns the hue value for a custom color.

创建自定义颜色#

To use a custom color, you must first create a Color object using one of the following constructors:

Hexadecimal String#

使用 Web 颜色字符串(十六进制代码)创建颜色。

Usage:
Color(value)

范围

描述

value

A six-digit hexidecimal code as a string (e.g., “#FF700” for yellow).

# Construct a yellow Color "yellow" using a
# hexadecimal string
yellow = Color("#FFF700")

controller.screen.set_pen_color(yellow)
controller.screen.print("My Yellow")

Hexadecimal Integer#

使用六位十六进制整数创建颜色。

Usage:
Color(value)

范围

描述

value

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

# Construct a yellow Color "yellow" using a
# hexadecimal integer
yellow = Color(0xFFF700)

controller.screen.set_pen_color(yellow)
controller.screen.print("My Yellow")

RGB#

使用单独的红色、绿色和蓝色值创建颜色。

Usage:
Color(r, g, b)

范围

描述

r

代表红色成分的 0 到 255 之间的整数。

g

代表绿色成分的 0 到 255 之间的整数。

b

代表蓝色成分的 0 到 255 之间的整数。

# Construct a yellow Color "yellow" using
# RGB values
yellow = Color(255, 247, 0)

controller.screen.set_pen_color(yellow)
controller.screen.print("My Yellow")

修改器#

These methods allow you to modify a Color object after it has been created during a project.

rgb#

rgb updates the color of an existing Color object using RGB values.

Usage:
rgb(r, g, b)

参数

描述

r

0 到 255 之间的整数,表示颜色的红色成分。

g

0 到 255 之间的整数,表示颜色的绿色成分。

b

0 到 255 之间的整数,表示颜色的蓝色成分。

# Create a custom teal color
my_fill_color = Color(50, 200, 180)

# Draw a teal rectangle
controller.screen.draw_rectangle(x=30, y=70, width=80, height=50, color=my_fill_color)

# Draw a magenta rectangle
my_fill_color.rgb(170, 40, 150)
controller.screen.draw_rectangle(x=130, y=70, width=80, height=50, color=my_fill_color)

hsv#

hsv updates the color of an existing Color object using HSV values.

Note: hsv can only be used to change a Color object that has already been created. It cannot be used to create a new Color Object.

Usage:
hsv(h, s, v)

参数

描述

h

表示颜色色调的 0 到 360 之间的整数。

s

0.0 到 1.0 之间的浮点数,表示颜色的饱和度。

v

0.0 到 1.0 之间的浮点数,表示颜色的亮度。

# Create a custom teal color
my_fill_color = Color(50, 200, 180)

# Draw a teal rectangle
controller.screen.draw_rectangle(x=30, y=70, width=80, height=50, color=my_fill_color)

# Draw a magenta rectangle
my_fill_color.hsv(300, 0.75, 0.78)
controller.screen.draw_rectangle(x=130, y=70, width=80, height=50, color=my_fill_color)

web#

web updates the color of an existing Color object using a web color (hex code).

Usage:
web(value)

参数

描述

value

用于更新现有颜色实例的字符串形式的 Web 颜色(十六进制代码)。

# Create a custom teal color
my_fill_color = Color("#32C8B6")

# Draw a teal rectangle
controller.screen.draw_rectangle(x=30, y=70, width=80, height=50, color=my_fill_color)

# Draw a magenta rectangle
my_fill_color.web("#AA2896")
controller.screen.draw_rectangle(x=130, y=70, width=80, height=50, color=my_fill_color)

吸气剂#

saturation#

saturation returns the saturation value for a custom color as a float from 0 to 1.

Usage:
my_color.saturation()

Replace my_color with the name of the custom color object.

参数

描述

该方法没有参数。

# Create a custom teal color
color_teal = Color(50, 200, 180)

# Display the saturation value of teal
controller.screen.print(color_teal.saturation())

hue#

hue returns the hue value for a custom color as a float from 0 to 359.

Usage:
my_color.hue()

Replace my_color with the name of the custom color object.

参数

描述

该方法没有参数。

# Create a custom teal color
color_teal = Color(50, 200, 180)

# Display the hue value of teal
controller.screen.print(color_teal.hue())