Pantalla#

Introducción#

La pantalla del controlador de drones VEX AIR proporciona métodos para mostrar texto, administrar el cursor, dibujar formas y manejar interacciones táctiles.

A continuación se muestra una lista de todos los métodos disponibles:

Impresión del cursor: muestra el texto utilizando un sistema de filas y columnas.

  • print – Prints text at the current cursor position.

  • set_cursor – Sets the cursor to a specific row and column.

  • next_row – Moves the cursor to column 1 of the next row.

  • clear_row – Clears a row of text.

  • get_row – Returns the current cursor row.

  • get_column – Returns the current cursor column.

Impresión XY: muestra el texto en una coordenada de pantalla específica.

  • print_at – Prints text at a specific x and y location.

  • set_origin – Sets a new origin for printing and drawing.

Mutadores: limpia la pantalla o actualiza la configuración visual.

Dibujar – Agregar gráficos e imágenes a la pantalla.

Táctil: detecta y responde a las pulsaciones de la pantalla.

  • pressing – Returns whether the screen is currently being pressed.

  • x_position – Returns the x-coordinate where the screen is pressed.

  • y_position – Returns the y-coordinate where the screen is pressed.

Devolución de llamada: ejecuta funciones cuando se presiona o suelta la pantalla.

  • pressed – Registers a function to call when the screen is pressed.

  • released – Registers a function to call when the screen is released.

Cursor Imprimir#

print#

print displays text on the controller’s screen at the current cursor position and font.

Usage:
controller.screen.print(text)

Parámetros

Descripción

text

El texto, número o valor de variable que se mostrará en la pantalla.

sep

Optional. The separator between printed text. By default, sep = ’ ‘

end

Optional. The string appended after the last printed text. By default, end = ‘\n’

precision

Optional. The number of decimals a float will print with as an integer. By default, precision = 5

# Display a message at the starting cursor position.
controller.screen.print("Time to fly!")

Muestra el método drone.screen.print con la palabra "¡Hora de volar!"

# Display the first 2 decimals of pi
controller.screen.print(3.1415, precision = 2)

Muestra el método drone.screen.print con el pi en 2 decimales

set_cursor#

set_cursor places the text cursor at a specific row and column on the screen. The number of rows and columns that fit depends on the selected font. With the default monospaced medium font, the screen can clearly display up to 11 rows and 53 columns. Text placed beyond this range may be cut off or harder to read.

Usage:
controller.screen.set_cursor(row, col)

Parámetros

Descripción

row

La fila del cursor.

column

La columna del cursor.

# Display text starting at Row 7 Column 25.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print("Row 7, Column 25")

Muestra el método drone.screen.print_at con la Fila 7, Columna 25 impresa en la fila 3, columna 2

next_row#

next_row moves the cursor to column 1 on the next row on the controller’s screen.

Usage:
controller.screen.next_row()

Parámetros

Descripción

Este método no tiene parámetros.

# Display two lines of text.
controller.screen.print("Line 1")
controller.screen.next_row()
controller.screen.print("Line 2")

Muestra el método controller.screen.next_row con la Línea 1 y la Línea 2 impresas en la pantalla del dron en la línea 1 y la línea 2 respectivamente.

clear_row#

clear_row clears a row of text on the controller’s screen.

Usage:
controller.screen.clear_row(row, color)

Parámetro

Descripción

row

Opcional. La fila que se va a borrar. El valor predeterminado es la fila actual del cursor.

color

Optional. The color to apply to the cleared row. If a color is not specified, the set_fill_color is used. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Clear only the second row of text
controller.screen.print("This text stays")
controller.screen.next_row()
controller.screen.print("This text disappears")
wait(3, SECONDS)
controller.screen.clear_row(2)

# Turn the 5th row green.
controller.screen.clear_row(5, GREEN)

get_row#

get_row returns the current row where text will be printed, as an integer.

Usage:
controller.screen.get_row()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the cursor's current row.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_row())

Muestra el método drone.screen.print_at mostrando la columna número 7 cuando establece curSor en 7,25

get_column#

get_column returns the current column where text will be printed, as an integer.

Usage:
controller.screen.get_column()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the cursor's current column.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_column())

Muestra el método drone.screen.print_at mostrando la columna número 25 cuando establece curSor en 7,25

Impresión XY#

set_origin#

set_origin sets the origin (0, 0) used for drawing or printing on the controller’s screen. By default, drawing or printing methods consider the top left corner of the screen as the origin. This method can reset the origin to an alternate (x, y) screen coordinate location.

Usage:
controller.screen.set_origin(x, y)

Parámetro

Descripción

x

La nueva coordenada x que se establecerá como origen, expresada como un entero de 0 a 640.

y

La nueva coordenada y que se establecerá como origen, expresada como un número entero entre 0 y 480.

# Set the origin to the center of the screen.
controller.screen.set_origin(x=320, y=240)

# Draw a rectangle at the new origin.
controller.screen.draw_rectangle(x=0, y=0, width=80, height=40)

La pantalla del controlador muestra un rectángulo blanco con la esquina superior izquierda en el centro.

Mutadores#

clear_screen#

clear_screen clears the controller’s screen of all drawings, text, and images.

Usage:
controller.screen.clear_screen(row, col, color)

Parámetro

Descripción

row

Opcional. La posición x donde se colocará el cursor después de borrar la pantalla. El valor predeterminado es 1.

col

Opcional. La posición y donde se colocará el cursor después de borrar la pantalla. El valor predeterminado es 1.

color

Optional. Sets the screen color. To use, you must include all three optional parameters. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw a circle, and clear it after 2 seconds.
controller.screen.draw_circle(x=320, y=240, radius=80)
wait(2, SECONDS)
controller.screen.clear_screen()

# Print two messages in the same spot
controller.screen.print("Hello!")
wait(3,SECONDS)
controller.screen.clear_screen(row=1, col=1)
controller.screen.print("Goodbye!")

# Set the background color of the screen to red.
controller.screen.clear_screen(RED)

wait_for_render#

wait_for_render prevents any following commands from running until all previous drawing and print commands on the screen have finished rendering.

Usage:
controller.screen.wait_for_render()

Parámetro

Descripción

Este método no tiene parámetros.

# Display text and images when button 7 is pressed.
controller.screen.wait_for_render()
controller.screen.print("Screen rendered!")
controller.screen.draw_circle(x=320, y=240, radius=80)
while not controller.button7.pressing():
    wait(5, MSEC)
controller.screen.wait_for_render()

La pantalla del controlador muestra un rectángulo blanco con la esquina superior izquierda en el centro.

set_font#

set_font sets the font used for displaying text on the controller’s screen. This font will apply to all text printed with print or print_at. The default font at the start of a project is MONO20.

Usage:
controller.screen.set_font(fontname)

Parámetro

Descripción

fontname

Sets the font to one of the following:

  • MONO12
  • MONO15
  • MONO20
  • MONO24
  • MONO30
  • MONO36
  • MONO40
  • MONO60
  • PROP20
  • PROP24
  • PROP30
  • PROP36
  • PROP40
  • PROP60

El controlador imprimió números y letras en la fuente MONO 12. En la parte inferior de la pantalla, tiene 90 de ancho y 37 filas.
MONO12

El controlador imprimió números y letras en la fuente MONO 15. En la parte inferior de la pantalla, tiene 70 caracteres de ancho y 28 filas.
MONO15

El controlador imprimió números y letras en la fuente MONO 20. En la parte inferior de la pantalla, tiene 52 caracteres de ancho y 22 filas.
MONO20

El controlador imprimió números y letras en la fuente MONO 24. En la parte inferior de la pantalla, tiene 44 caracteres de ancho y 18 filas.
MONO24

El controlador imprimió números y letras en pantalla con la fuente MONO 30. En la parte inferior de la pantalla, tiene 34 caracteres de ancho y 14 filas.
MONO30

El controlador imprimió números y letras con la fuente MONO 36. En la parte inferior de la pantalla, tiene 28 caracteres de ancho y 12 filas.
MONO36

El controlador imprimió números y letras en pantalla con la fuente MONO 40. En la parte inferior de la pantalla, tiene 25 caracteres de ancho y 11 filas.
MONO40

El controlador imprimió números y letras en la fuente MONO 60. En la parte inferior de la pantalla, tiene 16 caracteres de ancho y 7 filas.
MONO60

El controlador imprimió números y letras en pantalla con la fuente PROP 20. En la parte inferior de la pantalla, tiene 58 caracteres de ancho y 22 filas.
PROP20

El controlador imprimió números y letras en la pantalla con la fuente PROP 24. En la parte inferior de la pantalla, tiene 45 de ancho y 18 filas.
PROP24

El controlador imprimió números y letras en pantalla con la fuente PROP 30. En la parte inferior de la pantalla, tiene 37 caracteres de ancho y 14 filas.
PROP30

El controlador imprimió números y letras en la pantalla con la fuente PROP 36. En la parte inferior de la pantalla, tiene 30 caracteres de ancho y 12 filas.
PROP36

El controlador imprimió números y letras en pantalla con la fuente PROP 40. En la parte inferior de la pantalla, tiene 28 caracteres de ancho y 11 filas.
PROP40

El controlador imprimió números y letras en la pantalla con la fuente PROP 60. En la parte inferior, la pantalla tiene 19 caracteres de ancho y 7 filas.
PROP60

# Display text using a larger font.
controller.screen.set_font(MONO40)
controller.screen.print("VEX")

La pantalla del controlador muestra la palabra VEX en fuente Mono 40 en la esquina superior izquierda.

set_pen_width#

set_pen_width sets the pen width used for drawing lines and shapes.

Usage:
controller.screen.set_pen_width(width)

Parámetro

Descripción

width

El ancho del lápiz, expresado como un número entero en píxeles.

# Draw a rectangle with a pen width of 10.
controller.screen.set_pen_width(10)
controller.screen.draw_rectangle(x=200, y=200, width=200, height=80)

La pantalla del controlador muestra un rectángulo con un borde grueso dibujado.

set_pen_color#

set_pen_color sets the pen color used for drawing lines, shapes, and printing text.

Usage:
controller.screen.set_pen_color(color)

Parámetro

Descripción

color

Optional. Sets the pen color. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw a rectangle with an orange outline.
controller.screen.set_pen_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=240, height=150)
controller.screen.set_pen_color(WHITE)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

La pantalla del controlador muestra un rectángulo naranja con un borde fino y VEXcode AIR en blanco en el centro.

set_text_fill_color#

set_text_fill_color sets the highlight color used when text is printed. The default highlight color is transparent.

Usage:
controller.screen.set_text_fill_color(color)

Parámetro

Descripción

color

Optional. Sets the text highlight color. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Display two colors behind text
controller.screen.set_text_fill_color(RED)
controller.screen.print("Red")
controller.screen.next_row()
controller.screen.set_text_fill_color(BLUE)
controller.screen.print("Blue")

La pantalla del controlador muestra dos líneas con "rojo" y "azul" con el color correspondiente resaltando el texto.

set_fill_color#

set_fill_color sets the fill color used when shapes are drawn. The default fill color is black.

Usage:
controller.screen.set_fill_color(color)

Parámetro

Descripción

color

Optional. Sets the fill color. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw an orange-filled rectangle with text on top
controller.screen.set_fill_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=250, height=150)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

La pantalla del controlador muestra un rectángulo naranja con borde blanco, con un borde fino y VEXcode AIR en blanco en el centro.

Dibujar#

draw_pixel#

draw_pixel draws a pixel at the specified (x, y) screen coordinate in the current pen color. It uses the current pen color set by set_pen_color.

Usage:
controller.screen.draw_pixel(x, y)

Parámetro

Descripción

x

La coordenada x donde se dibujará el píxel, expresada como un número entero de 0 a 640.

y

La coordenada y donde se dibujará el píxel, expresada como un número entero de 0 a 480.

# Draw five pixels in a diagonal.
controller.screen.draw_pixel(x=360, y=200)
controller.screen.draw_pixel(x=340, y=220)
controller.screen.draw_pixel(x=320, y=240)
controller.screen.draw_pixel(x=300, y=260)
controller.screen.draw_pixel(x=280, y=280)

La pantalla del controlador muestra cinco píxeles impresos en blanco en una línea.

draw_line#

draw_line draws a line from the first specified screen coordinate (x1, y1) to the second specified screen coordinate (x2, y2). It uses the current the pen width set by set_pen_width and pen color set by set_pen_color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

Usage:
controller.screen.draw_line(x1, y1, x2, y2)

Parámetro

Descripción

x1

La coordenada x inicial de la línea, expresada como un número entero entre 0 y 640.

y1

La coordenada y inicial de la línea, expresada como un número entero entre 0 y 480.

x2

La coordenada x final de la línea, expresada como un número entero entre 0 y 640.

y2

La coordenada y final de la línea, expresada como un número entero entre 0 y 480.

# Make an X across the screen.
controller.screen.draw_line(x1=0, y1=0, x2=640, y2=480)
controller.screen.set_pen_color(CYAN)
controller.screen.draw_line(x1=0, y1=480, x2=640, y2=0)

La pantalla del controlador muestra una X en el centro.

draw_rectangle#

draw_rectangle draws a rectangle with its top-left corner at the specified (x, y) coordinate and a size determined by the given width and height, all measured in pixels. The rectangle’s outline is drawn using the current pen width set by set_pen_width and the pen color set by set_pen_color. The interior is filled with the color set by set_fill_color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

Usage:
controller.screen.draw_rectangle(x, y, width, height, color)

Parámetro

Descripción

x

La coordenada x de la esquina superior izquierda del rectángulo, expresada como un número entero de 0 a 640.

y

La coordenada y de la esquina superior izquierda del rectángulo, expresada como un número entero de 0 a 480.

width

El ancho del rectángulo, expresado como un número entero de 0 a 640.

height

La altura del rectángulo, expresada como un número entero de 0 a 480.

color

Optional. Sets the fill color of the rectangle. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw two rectangles on the screen.
controller.screen.draw_rectangle(x=0, y=0, width=620, height=460)
controller.screen.draw_rectangle(x=200, y=180, width=200, height=100, color=GREEN)

La pantalla del controlador muestra un rectángulo verde con un borde blanco delgado rodeado por un rectángulo más grande con borde blanco.

draw_circle#

draw_circle draws a circle with its center at the specified (x, y) coordinate and a size determined by the given radius, all measured in pixels. The circle’s outline is drawn using the current pen width set by set_pen_width and the pen color set by set_pen_color. The interior is filled with the color set by set_fill_color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

Usage:
controller.screen.draw_circle(x, y, radius, color)

Parámetro

Descripción

x

La coordenada x del centro del círculo, expresada como un número entero de 0 a 640.

y

La coordenada y del centro del círculo, expresada como un número entero de 0 a 480.

radius

El radio del círculo, expresado como un número entero de 0 a 480 píxeles.

color

Optional. Sets the fill color of the circle. Options include:

  • BLAC
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw one green circle on the screen.
controller.screen.set_fill_color(GREEN)
controller.screen.draw_circle(x=320, y=240, radius=200, color=GREEN)

La pantalla del controlador muestra un círculo verde con un borde blanco delgado dibujado en el centro.

show_file#

show_file draws a custom uploaded image on the controller’s screen, with its position set using the x, y, and center parameters based on the image’s reference point.

Usage:
controller.screen.show_file(file, x, y, scale_width, scale_height, rotate, use_alpha)

Parámetro

Descripción

file

La imagen subida por el usuario que se usará. Las opciones cambiarán si se editan los nombres de las imágenes en el Panel de control.

x

El desplazamiento horizontal de la imagen, expresado como un entero en píxeles. Los valores positivos lo desplazan hacia la derecha; los negativos, hacia la izquierda.

y

El desplazamiento vertical de la imagen, expresado como un entero en píxeles. Los valores positivos lo desplazan hacia abajo; los negativos, hacia arriba.

scale_width

Opcional. El ancho de la imagen a la que se escala, expresado como un entero en píxeles.

scale_height

Opcional. La altura de la imagen a la que se escala, expresada como un entero en píxeles.

rotation

Opcional. El grado de rotación de la imagen, expresado como un número entero entre 0 y 359.

use_alpha

Optional. Use alpha channel for image to show transparent. Options include:

  • True
  • False

# Display uploaded Image 1 in the top left corner.
controller.screen.show_file(IMAGE1, x=0, y=0)

# Display uploaded Image 1 scaled to the full screen.
controller.screen.show_file(IMAGE1, x=65, y=0, scale_width=640, scale_height=480)

# Display uploaded Image 1 with rotation of 180 degrees.
controller.screen.show_file(IMAGE1, x=-65, y=0, rotation=180)

# Upload an image with a transparent background.
# Display uploaded Image 1 with alpha channel enabled.
controller.screen.show_file(IMAGE1, x=0, y=0, use_alpha=True)

Tocar#

pressing#

pressing returns whether the controller’s screen is currently being pressed as a Boolean:

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

Usage:
controller.screen.pressing()

Parámetros

Descripción

Este método no tiene parámetros.

# Play a sound when the screen is pressed.
while True:
    if controller.screen.pressing():
        controller.sound.play_note("C5", 500)
    wait(5, MSEC)

x_position#

x_position returns the x-coordinate in pixels where the screen was pressed, as an integer from 0 (left) to 640 (right).

Un controlador VEX AIR está encendido y orientado hacia adelante. Las dimensiones de la pantalla se muestran en los bordes de un recuadro rojo resaltado. La parte superior izquierda es (0, 0), la superior derecha es (640, 0), la inferior izquierda es (0, 480), la inferior derecha es (640, 480) y el centro es (320, 240).

Usage:
controller.screen.x_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Play a high or low note based on where screen is pressed.
while True:
    if controller.screen.pressing():
        if controller.screen.x_position() > 320:
            controller.sound.play_note("C6", 500)
        else:
            controller.sound.play_note("C4", 500)
    wait(5, MSEC)

y_position#

y_position returns the y-coordinate in pixels where the screen was pressed, as an integer from 0 (top) to 480 (bottom).

Un controlador VEX AIR está encendido y orientado hacia adelante. Las dimensiones de la pantalla se muestran en los bordes de un recuadro rojo resaltado. La parte superior izquierda es (0, 0), la superior derecha es (640, 0), la inferior izquierda es (0, 480), la inferior derecha es (640, 480) y el centro es (320, 240).

Usage:
controller.screen.y_position()

# Play a high or low note based on where screen is pressed.
while True:
    if controller.screen.pressing():
        if controller.screen.y_position() > 240:
            controller.sound.play_note("C6", 500)
        else:
            controller.sound.play_note("C4", 500)
    wait(5, MSEC)

Llamar de vuelta#

pressed#

pressed registers a method to be called when the controller’s screen is pressed.

Usage:
controller.screen.pressed(callback, arg)

Parámetros

Descripción

callback

Una función que se define previamente para ejecutarse cuando cambia el valor del eje.

arg

Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Uso de funciones con parámetros para obtener más información.

# Play a sound when the screen is pressed.
def play_sound():
    controller.sound.play_note("C5", 500)

controller.screen.pressed(play_sound)

released#

released registers a method to be called when the screen is no longer being pressed.

Usage:
controller.screen.released(callback, arg)

Parámetros

Descripción

callback

Una función que se define previamente para ejecutarse cuando cambia el valor del eje.

arg

Opcional. Una tupla que contiene los argumentos que se pasan a la función de devolución de llamada. Consulte Uso de funciones con parámetros para obtener más información.

# Play a sound when the screen is pressed.
def play_sound():
    controller.sound.play_note("C5", 500)
    
controller.screen.released(play_sound)