Pantalla#

Introducción#

La pantalla del robot de codificación VEX AIM 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:

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.

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

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

  • pressing – Returns whether the screen is currently being 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 robot’s screen at the current cursor position and font.

Usage:
robot.screen.print(text)

Parámetros

Descripción

text

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

# Display a message at the starting cursor position
robot.screen.print("Hello, Robot!")

Captura de pantalla de la pantalla del robot, con "¡Hola, robot!" impreso en blanco en la parte superior.

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 8 rows and 13 columns. Text placed beyond this range may be cut off or harder to read.

Monospaced fonts have characters that are all the same width, making text placement consistent. In contrast, proportional fonts vary in character width, so some letters take up more space than others. However, regardless of which type is used, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using set_font.

Usage:
robot.screen.set_cursor(row, column)

Parámetros

Descripción

row

La fila del cursor.

column

La columna del cursor.

# Display text starting at Row 3 Column 2
robot.screen.set_cursor(3, 2)
robot.screen.print("Row 3, Column 2")

Captura de pantalla de la pantalla del robot, con "Fila 3, Columna 2" impreso en blanco justo encima del centro de la pantalla, comenzando en la fila 3, columna 2.

next_row#

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

Usage:
robot.screen.next_row()

Parámetros

Descripción

Este método no tiene parámetros.

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

Captura de pantalla de la pantalla del robot con texto blanco. La pantalla muestra la Línea 1 en la línea superior, alineada a la izquierda, y la Línea 2 justo debajo.

clear_row#

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

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

Parámetro

Descripción

row

Opcional. La fila que se va a borrar como un número entero. Por defecto, se utiliza la fila actual del cursor.

color

Optional. The color to apply to the cleared row. Options include:

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

# Display text on two rows
robot.screen.print("This text stays")
robot.screen.next_row()
robot.screen.print("This text disappears")

# Wait 3 seconds before clearing only the second row
wait(3, SECONDS)
robot.screen.clear_row()

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

Captura de pantalla de la pantalla del robot con una barra verde que cruza el centro de la pantalla de izquierda a derecha.

get_row#

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

Usage:
robot.screen.get_row()

Parámetros

Descripción

Este método no tiene parámetros.

# Set cursor to (3,2) and print row number
robot.screen.set_cursor(3, 2)
robot.screen.print(robot.screen.get_row())

Captura de pantalla de SA de la pantalla del robot, con un 3 blanco impreso cerca del centro del cuadrante superior izquierdo, en la fila 3, columna 2.

get_column#

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

Usage:
robot.screen.get_column()

Parámetros

Descripción

Este método no tiene parámetros.

# Set cursor to (3,2) and print column number
robot.screen.set_cursor(3, 2)
robot.screen.print(robot.screen.get_column())

Captura de pantalla de la pantalla del robot, con un 2 blanco impreso cerca del centro del cuadrante superior izquierdo, en la fila 3, columna 2.

Impresión XY#

set_origin#

set_origin establece el origen (0, 0) utilizado para dibujar o imprimir en la pantalla del robot. Por defecto, los métodos de dibujo o impresión consideran la esquina superior izquierda de la pantalla como origen. Este método puede restablecer el origen a una ubicación alternativa de coordenadas (x, y) en la pantalla.

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

Parámetro

Descripción

x

La nueva coordenada x que se establecerá como origen, expresada como un número entero de 0 a 240.

y

La nueva coordenada y que se establecerá como origen, expresada como un número entero de 0 a 240.

# Set the origin to the center of the screen
robot.screen.set_origin(120, 120)

# Draw a rectangle at the new origin
robot.screen.draw_rectangle(0, 0, 80, 40)

Captura de pantalla de la pantalla del robot con un rectángulo blanco dibujado en el cuadrante inferior izquierdo. La esquina superior izquierda del rectángulo es el centro de la pantalla.

Mutadores#

clear_screen#

clear_screen clears all drawings and text from the robot’s screen. By default, it also resets the cursor position to row 1, column 1.

Usage:
robot.screen.clear_screen(color)

Parámetro

Descripción

color

Optional. Sets the screen color. 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
robot.screen.draw_circle(120, 120, 60)
wait(2, SECONDS)
robot.screen.clear_screen()

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

Captura de pantalla de la pantalla del robot, mostrando toda la pantalla en rojo brillante.

set_font#

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

Usage:
robot.screen.set_font(fontname)

Parámetro

Descripción

fontname

Sets the font to one of the following:

  • MONO12
  • MONO15
  • MONO20
  • MONO24
  • MONO30
  • MONO40
  • MONO60
  • PROP20
  • PROP30
  • PROP40
  • PROP60
These options are shown below.

Captura de pantalla de la pantalla del robot que muestra una muestra de números y letras impresos en fuente Mono 12. El alfabeto ocupa una fila de texto. En la parte inferior se leen 26 caracteres de ancho y 15 filas.
MONO12

La misma imagen que la anterior con la fuente Mono 15. Las letras AT abarcan una fila de texto. En la parte inferior se leen 20 caracteres de ancho y 12 filas.
MONO15

La misma imagen que la anterior, con la fuente Mono 20. Las letras AP ocupan una fila de texto. En la parte inferior se leen 16 caracteres de ancho y 9 filas.
MONO20

La misma imagen que la anterior, con la fuente Mono 24. Las letras AM ocupan una fila de texto. En la parte inferior se leen 13 caracteres de ancho y 8 filas.
MONO24

La misma imagen que la anterior, con la fuente Mono 30. Las letras AK ocupan una fila de texto. En la parte inferior se leen 11 caracteres de ancho y 6 filas.
MONO30

Misma imagen que la anterior, con fuente Mono 40. Las letras AH ocupan una fila de texto. En la parte inferior se leen 8 caracteres de ancho y 5 filas.
MONO40

La misma imagen que la anterior, con los números impresos en fuente Mono 60. Los números del 1 al 6 ocupan una fila de texto. En la parte inferior se leen tres filas.
MONO60

Misma imagen que la anterior, con la fuente Prop 20. Las letras A abarcan una fila de texto. En la parte inferior se leen 20 caracteres de ancho y 9 filas.
PROP20

Misma imagen que la anterior, con la fuente de la Propuesta 30. Las letras AM ocupan una fila de texto. En la parte inferior se leen 15 caracteres de ancho y 6 filas.
PROP30

La misma imagen que la anterior, con la fuente de la Propuesta 40. Las letras AJ ocupan una fila de texto. En la parte inferior se leen 11 caracteres de ancho y 5 filas.
PROP40

La misma imagen que la anterior, con los números impresos en la fuente de la Propuesta 60. Los números del 1 al 7 ocupan una fila de texto. En la parte inferior se lee 7 por 3.
PROP60

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

Una captura de pantalla de la pantalla del robot muestra VEX en fuente Mono 40 en la esquina superior izquierda.

set_pen_width#

set_pen_width establece el ancho del lápiz utilizado para dibujar líneas y formas.

Usage:
robot.screen.set_pen_width(width)

Parámetro

Descripción

width

El ancho del lápiz, expresado como un número entero en píxeles en un rango de 0 a 32.

# Draw a rectangle with a pen width of 10
robot.screen.set_pen_width(10)
robot.screen.draw_rectangle(50, 50, 130, 60)

Captura de pantalla de la pantalla del robot con un grueso rectángulo blanco dibujado en la mitad superior.

set_pen_color#

set_pen_color establece el color del lápiz utilizado para dibujar líneas, formas y texto.

Usage:
robot.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 a red pen
robot.screen.set_pen_color(RED)
robot.screen.draw_rectangle(50, 50, 130, 60)

Captura de pantalla de la pantalla del robot con un rectángulo rojo de borde fino dibujado en la mitad superior.

set_fill_color#

El método set_fill_color establece el color de relleno utilizado cuando se dibujan formas.

Usage:
robot.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 two orange rectangles
robot.screen.set_fill_color(ORANGE)
robot.screen.draw_rectangle(50, 50, 100, 60)
robot.screen.draw_rectangle(50, 130, 100, 60)

Captura de pantalla de la pantalla del robot con dos rectángulos naranjas paralelos con finos contornos blancos situados en el centro izquierdo de la pantalla.

# Display text with a purple background
robot.screen.set_fill_color(PURPLE)
robot.screen.print("Highlight")

Una captura de pantalla de la pantalla del robot muestra la palabra "Resaltar" en texto blanco con un resaltado morado a su alrededor, comenzando en la esquina superior izquierda.

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:
robot.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 240.

y

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

# Draw a pixel at the center of the screen
robot.screen.draw_pixel(120, 120)

Captura de pantalla de la pantalla del robot con un solo píxel blanco en el centro.

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:
robot.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 240.

y1

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

x2

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

y2

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

# Draw a line from the top left to bottom right of the screen
robot.screen.draw_line(0, 0, 240, 240)

Captura de pantalla de la pantalla del robot con una fina línea diagonal blanca dibujada desde la esquina superior izquierda hasta la esquina inferior derecha.

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:
robot.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 240.

y

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

width

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

height

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

color

Optional. 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 a red rectangle on the screen
robot.screen.draw_rectangle(50, 50, 130, 60, RED)

Captura de pantalla de la pantalla del robot con un rectángulo rojo brillante con un borde blanco delgado centrado en la mitad superior de la pantalla.

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:
robot.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 240.

y

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

radius

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

color

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

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

# Draw a green circle on the screen
robot.screen.draw_circle(120, 120, 40, GREEN)

Captura de pantalla de la pantalla del robot con un círculo verde brillante con un borde blanco fino en el centro.

show_file#

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

Usage:
robot.screen.show_file(file, x, y, center)

Parámetro

Descripción

file

The custom image to use, from IMAGE1 to IMAGE10. The image number matches the number shown in the AIM control panel.

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.

center

Optional. If center=True, the image is placed using its center at coordinate (120, 120). By default (center=False), the top-left corner of the image is used and positioned relative to the current origin.

# Display uploaded Image 1 in the top left corner
robot.screen.show_file(IMAGE1, 0, 0)

# Show the same image on both sides of the screen
# Image size is 120 x 120
robot.screen.show_file(IMAGE1, 65, 0, center=True)
robot.screen.show_file(IMAGE1, -65, 0, center=True)

set_clip_region#

set_clip_region defines a rectangular area on the screen where all drawings and text will be confined. Any content outside this region will not be displayed.

Usage:
robot.screen.set_clip_region(x, y, width, height)

Parámetro

Descripción

x

La coordenada x de la esquina superior izquierda de la región de recorte, expresada como un número entero o flotante de 0 a 240.

y

La coordenada y de la esquina superior izquierda de la región de recorte, expresada como un número entero o flotante de 0 a 240.

width

El ancho de la región de recorte en píxeles, expresado como un número entero o flotante de 0 a 240.

height

La altura de la región de recorte en píxeles, expresada como un entero o un punto flotante entre 0 y 240.

# Restrict text and drawings to a specific region
robot.screen.set_clip_region(0, 0, 120, 120)
robot.screen.draw_rectangle(60, 60, 100, 100, RED)
robot.screen.print_at("Cut off!", x=60, y=60)

Captura de pantalla de la pantalla del robot que muestra el texto y la imagen que se ajustan a la región de recorte. En el cuadrante superior izquierdo, el texto blanco dice “Cortar o”, con un cuadrado rojo justo debajo.

Tocar#

pressing#

pressing returns a Boolean indicating whether the screen is currently being pressed.

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

Usage:
robot.screen.pressing()

Parámetros

Descripción

Este método no tiene parámetros.

# Turn LEDs white only while the screen is pressed.
while True:
    if robot.screen.pressing():
        robot.led.on(ALL_LEDS, WHITE)
    else: 
        robot.led.off(ALL_LEDS)

    wait(50, MSEC)

# Display different messages after the screen is pressed
while not robot.screen.pressing():
    wait(5, MSEC)
robot.screen.print("First message!")
robot.screen.next_row()
# Lift finger to press the screen again
while robot.screen.pressing():
    wait(5, MSEC)
while not robot.screen.pressing():
    wait(5, MSEC)
robot.screen.print("Second message!")
robot.screen.next_row()

x_position#

x_position returns the x-coordinate where the screen is pressed as an integer from 0 (left) to 240 (right).

Usage:
robot.screen.x_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the x-coordinate of where
# the screen is pressed
while True:
    if robot.screen.pressing():
        robot.screen.clear_screen()
        robot.screen.print(robot.screen.x_position())
    wait (50, MSEC)

y_position#

y_position returns the y-coordinate where the screen is pressed as an integer from 0 (top) to 240 (bottom).

Usage:
robot.screen.y_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the y-coordinate of where
# the screen is pressed
while True:
    if robot.screen.pressing():
        robot.screen.clear_screen()
        robot.screen.print(robot.screen.y_position())
    wait (50, MSEC)

Llamar de vuelta#

pressed#

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

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

Parámetros

Descripción

callback

Un método que se llamará cuando se presione la pantalla.

arg

Opcional. Una tupla que contiene argumentos para pasar al método de devolución de llamada cuando se llama.

# Set the LEDs to green when the screen is pressed.
def screen_touched():
    robot.led.on(ALL_LEDS, GREEN)

robot.screen.pressed(screen_touched)

released#

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

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

Parámetros

Descripción

callback

Un método que se llamará cuando se suelte la pantalla.

arg

Opcional. Una tupla que contiene argumentos para pasar al método de devolución de llamada cuando se llama.

# Set the LEDs to blue when the screen is released.
def screen_released():
    robot.led.on(ALL_LEDS, BLUE)

robot.screen.released(screen_released)