Colores personalizados#

Introducción#

El VEX AIR Drone permite usar colores personalizados para dibujar e imprimir texto. Se pueden crear colores personalizados usando valores RGB o códigos hexadecimales. Los colores personalizados también incluyen métodos para actualizar objetos de color durante un proyecto.

A continuación se muestra una lista de constructores disponibles:

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.

Mutadores: actualizan un objeto Color existente.

  • 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").

Obtenedores: devuelven el valor de tono o saturación de un objeto de color.

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

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

Creando un color personalizado#

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

Hexadecimal String#

Crea un color utilizando una cadena de color web (código hexadecimal).

Usage:
Color(value)

Parámetro

Descripción

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#

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 integer
yellow = Color(0xFFF700)

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

RGB#

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
yellow = Color(255, 247, 0)

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

Mutadores#

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)

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

Parámetros

Descripción

h

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

s

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

v

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

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

Parámetros

Descripción

value

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

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

Captadores#

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.

Parámetros

Descripción

Este método no tiene parámetros.

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

Parámetros

Descripción

Este método no tiene parámetros.

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

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