Colores personalizados#
Introducción#
VEX IQ (2.ª generación) admite el uso de colores personalizados para dibujos y texto. Se pueden crear colores personalizados utilizando valores RGB, códigos hexadecimales, valores HSV o constantes predefinidas. Colores personalizados incluye métodos para crear y actualizar objetos de color. A continuación, se muestra una lista de los métodos disponibles:
Constructors – Create a new Color
object.
Color(value) – Accepts a predefined constant, hex string (e.g.
“#FFF700”
), or hex integer (e.g.0xFFF700
).Color(r, g, b) – Crea un color utilizando valores rojo, verde y azul (0–255).
Mutators – Update an existing Color
object.
Creando un color personalizado#
To use a custom color, you must first create a Color
object using one of the following constructors:
Hexadecimal Integer#
Crea un color utilizando un entero hexadecimal de seis dígitos.
Usage:
Color(value)
Parámetro |
Descripción |
---|---|
|
A six-digit integer in hexadecimal format (e.g., |
# Construct a yellow Color "yellow" using a
# hexadecimal value
yellow = Color(0xFFF700)
brain.screen.set_pen_color(yellow)
brain.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 |
---|---|
|
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. |
# Construct a yellow Color "yellow" using
# RGB values
yellow = Color(255, 247, 0)
brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")
Web Color#
Crea un color utilizando una cadena de color web (código hexadecimal).
Usage:
Color(value)
Parámetro |
Descripción |
---|---|
|
A web color as a string (hex code) (e.g., |
# Construct a yellow Color "yellow" using a
# web string
yellow = Color("#FFF700")
brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")
Predefined Color#
Creates a color using a predefined Color
constant.
Usage:
Color(value)
Parámetro |
Descripción |
---|---|
|
A built-in color constant: |
# Construct a yellow Color "yellow" using a
# predefined Color constant
yellow = Color.YELLOW
brain.screen.set_pen_color(yellow)
brain.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 |
---|---|
|
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. |
# Create a custom teal color and set it as the pen color
brain_color = Color(50, 200, 180)
brain.screen.set_pen_color(brain_color)
# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)
# Draw another rectangle with a magenta outline
brain_color.rgb(170, 40, 150)
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)
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 |
---|---|
|
Un número entero de 0 a 360 que representa el tono del color. |
|
Un flotante de 0,0 a 1,0 que representa la saturación del color. |
|
Un flotante de 0,0 a 1,0 que representa el brillo del color. |
# Create a custom teal color using RGB (HSV can't be used)
brain_color = Color(50, 200, 180)
brain.screen.set_pen_color(brain_color)
# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)
# Draw another rectangle with a magenta outline
brain_color.hsv(300, 0.75, 0.78)
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)
web#
web
updates the color of an existing Color
object using a web color (hex code).
Usage:
web(value)
Parámetros |
Descripción |
---|---|
|
Un color web (código hexadecimal) como una cadena utilizada para actualizar la instancia de color existente. |
# Create a custom teal color and set it as the pen color
brain_color = Color("#32C8B6")
brain.screen.set_pen_color(brain_color)
# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)
# Draw another rectangle with the new magenta outline
brain_color.web("#AA2896")
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)