Pantalla#

Introducción#

La categoría Pantalla controla la pantalla táctil del V5 Brain, lo que permite que su robot muestre texto, números y gráficos, y responda a la entrada táctil.

De forma predeterminada, la fuente para imprimir en Brain es monoespaciada pequeña, que tiene 12 filas y 48 columnas.

Para dibujar, la resolución del Cerebro es de 479 x 239 píxeles.

Un diagrama de cuadrícula etiquetado de la pantalla VEX Brain que muestra filas, columnas, dimensiones de píxeles y coordenadas, con líneas rojas que delinean la cuadrícula.

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

Cursor Imprimir — Colocar e imprimir texto.

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

  • row — Returns the current cursor row.

  • column — Returns the current cursor column.

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

  • get_string_width — Returns the width of a string in pixels.

  • get_string_height — Returns the height of a string in pixels.

  • clear_line — Clears a line of text.

  • new_line — Moves the cursor to a new line.

Mutadores: cambian la configuración de la pantalla, los colores y el comportamiento del dibujo.

  • clear_screen — Clears the screen of all drawings and text.

  • set_font — Sets the font for printed text.

  • set_pen_width — Sets the thickness for drawn shapes and lines.

  • set_pen_color — Sets the color for outlines and text.

  • set_fill_color — Sets the fill color for shapes and backgrounds.

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

Dibujar: agrega gráficos a la pantalla.

  • draw_pixel — Draws a pixel at a specific x and y position.

  • draw_line — Draws a line between two points.

  • draw_rectangle — Draws a rectangle.

  • draw_circle — Draws a circle.

  • render — Updates the Brain’s screen with text and drawings only when called.

  • set_clip_region — Restricts where drawings and text can appear.

Toque: recibe información táctil desde la pantalla.

  • pressing — Returns whether the screen is being pressed.

  • x_position — Returns the X coordinate of the last screen event.

  • y_position — Returns the Y coordinate of the last screen event.

Devoluciones de llamadas: responden a eventos táctiles en la pantalla.

  • pressed — Registers a function to be called when the screen is pressed.

  • released — Registers a function to be called when the screen is released.

For information on constructing a Brain to gain access to the screen methods, see Brain.

Cursor Imprimir#

print#

print prints text on the screen using the current cursor position.

Uso:

brain.screen.print(text, sep, precision)

Parámetros

Descripción

text

El texto a imprimir.

sep

Optional. A string to insert between values. This must be written as a keyword argument (sep=). The default is “”.

precision

Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument(precision=). The default is 2.

# Print on the Brain's screen
brain.screen.print("Hello, Robot!")

Una captura de pantalla del V5 Brain que muestra "Hola Pantalla" impreso en la pantalla.

set_cursor#

set_cursor sets the cursor position. The cursor is placed at a specific row and column on the screen. How many rows and columns can comfortably fit depends on the selected font. With the default monospaced medium font, up to 8 rows and 13 columns can be displayed clearly. Text placed beyond this range may be cut off or become difficult 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 the set_font.

Uso:

brain.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 12
brain.screen.set_cursor(3, 12)
brain.screen.print("Row 3, Column 12")

Una captura de pantalla del V5 Brain que muestra "Fila 3 Columna 12" impreso en la pantalla.

next_row#

next_row moves the cursor to the next row.

Uso:

brain.screen.next_row()

Parámetros

Descripción

Este método no tiene parámetros.

# Print two lines of text on the Brain's screen
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

Una captura de pantalla del V5 Brain que muestra el texto "Línea 1" impreso encima de "Línea 2".

clear_row#

clear_row(row, color) clears a row to a single color.

Uso:

brain.screen.clear_row(row, color)

Parámetros

Descripción

row

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

color

Opcional. Un color válido, un valor hexadecimal o una cadena web.

# Only keep the text on row 1
brain.screen.print("This text stays")
brain.screen.next_row
brain.screen.print("This text disappears")
wait(3, SECONDS)

brain.screen.clear_row()

row#

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

Uso:

brain.screen.row()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the cursor's current row
brain.screen.set_cursor(3, 2)
brain.screen.print(brain.screen.row())

Una captura de pantalla del V5 Brain que muestra el texto "3" en la fila 3.

column#

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

Uso:

brain.screen.column()

Parámetros

Descripción

Este método no tiene parámetros.

# Display the cursor's current column
brain.screen.set_cursor(5, 10)
brain.screen.print(brain.screen.column())

Una captura de pantalla del cerebro V5 que muestra el texto "10" en la columna 10.

get_string_width#

get_string_width(string) returns the width of a string in pixels as an integer as if it was on the Brain’s screen. The width of a string changes based on the length of the string and the size of the font.

Usage:
brain.screen.get_string_width(string)

Parámetros

Descripción

string

La cuerda a medir.

get_string_height#

get_string_height(string) returns the height of a string as an integer in pixels as if it was on the Brain’s screen. The height of a string changes based on the length of the string and the size of the font.

Usage:
brain.screen.get_string_height(string)

Parámetros

Descripción

string

La cuerda a medir.

clear_line#

clear_line clears the current row of text.

Usage: brain.screen.clear_line()

Parámetros

Descripción

Este método no tiene parámetros.

new_line#

new_line moves the cursor to a new line.

Uso:

brain.screen.new_line()

Parámetros

Descripción

Este método no tiene parámetros.

Mutadores#

clear_screen#

clear_screen(color) clears the whole screen to a single color.

Uso:

brain.screen.clear_screen(color)

Parámetros

Descripción

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.BLACK (Default)
  • Color.WHITE
# Print VEXcode on the screen
brain.screen.print("VEXcode")
wait(2, SECONDS)
# Clear screen to black
brain.screen.clear_screen()

# Print VEXcode on the screen
brain.screen.print("VEXcode")

# Clear screen to blue using predefined color
brain.screen.clear_screen(Color.BLUE)

Una captura de pantalla del V5 Brain con una pantalla azul.

set_font#

set_font(fontname) sets the font type used for printing text on the screen.

Uso:

brain.screen.set_font(font)

Parámetros

Descripción

font

Una opción de fuente válida a continuación.

El robot serigrafió números y letras con la fuente MONO 12. Se muestra de la A a la Z. En la parte inferior de la pantalla, tiene 26 de ancho y 15 filas.
FontType.MONO12

El robot serigrafió números y letras con la fuente MONO 15. Muestra AT. En la parte inferior de la pantalla, tiene 20 caracteres de ancho y 12 filas.
FontType.MONO15

El robot serigrafió números y letras con la fuente MONO 20. Muestra AP. En la parte inferior de la pantalla, mide 16 de ancho y 9 filas.
FontType.MONO20

El robot serigrafió números y letras con la fuente MONO 30. Muestra AK. En la parte inferior de la pantalla, mide 11 de ancho y 6 filas.
FontType.MONO30

El robot serigrafió números y letras con la fuente MONO 40. Muestra AK. En la parte inferior de la pantalla, tiene 8 caracteres de ancho y 5 filas.
FontType.MONO40

El robot serigrafió números y letras con la fuente MONO 60. Muestra del 1 al 6. En la parte inferior de la pantalla, consta de tres filas.
FontType.MONO60

El robot serigrafió números y letras con la fuente PROP 20. Muestra AS. En la parte inferior de la pantalla, tiene 8 caracteres de ancho y 9 filas.
FontType.PROP20

El robot serigrafió números y letras con la fuente PROP 30. Muestra AM. En la parte inferior de la pantalla, mide 15 de ancho y 6 filas.
FontType.PROP30

El robot serigrafió números y letras con la fuente PROP 40. Muestra AM. En la parte inferior de la pantalla, mide 15 de ancho y 6 filas.
FontType.PROP40

El robot serigrafió números y letras con la fuente PROP 60. Muestra del 1 al 7. En la parte inferior de la pantalla, tiene un 7 de ancho y 3 filas.
FontType.PROP60

# Set the font type to MONO40
brain.screen.set_font(FontType.MONO40)
brain.screen.print("VEX")

Una captura de pantalla del V5 Brain que muestra el texto "VEX" en una fuente más grande que la predeterminada.

set_pen_width#

set_pen_width(width) sets the pen width used for drawing lines, rectangles, and circles.

Uso:

brain.screen.set_pen_width(value)

Parámetros

Descripción

value

El ancho del lápiz en píxeles en un rango de 0 a 32.

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

Una captura de pantalla del V5 Brain que muestra un rectángulo con bordes gruesos.

set_pen_color#

set_pen_color sets the pen color used for drawing lines, rectangles, and circles.

Uso:

brain.screen.set_pen_color(color)

Parámetros

Descripción

color

A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# Draw a rectangle with orange borders
brain.screen.set_pen_color(Color.ORANGE)
brain.screen.draw_rectangle(50, 50, 130, 60)

Una captura de pantalla del V5 Brain que muestra un rectángulo con bordes naranjas.

set_fill_color#

set_fill_color sets the fill color used for drawing rectangles and circles.

Uso:

brain.screen.set_fill_color(color)

Parámetros

Descripción

color

A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# Draw a purple rectangle
brain.screen.set_fill_color(Color.PURPLE)
brain.screen.draw_rectangle(50, 130, 100, 60)

Una captura de pantalla del V5 Brain que muestra un rectángulo relleno de color púrpura.

set_origin#

set_origin sets the origin used for drawing graphics on the Brain’s screen. Drawing functions consider the top left corner of the Brain’s screen as the origin. This function can move the origin to an alternate position such as the center of the Brain’s screen.

Uso:

brain.screen.set_origin(x, y)

Parámetros

Descripción

x

La posición x del origen relativa a la esquina superior izquierda como un entero de 0 a 480.

y

La posición y del origen relativa a la esquina superior izquierda como un entero de 0 a 240.

Dibujar#

draw_pixel#

draw_pixel draws a pixel using the current pen color.

Uso:

brain.screen.draw_pixel(x, y)

Parámetros

Descripción

x

La posición x para dibujar el píxel referenciado al origen de la pantalla.

y

La posición y para dibujar el píxel referenciado al origen de la pantalla.

# Draw the pixels marking the corners of a square
brain.screen.draw_pixel(250, 100)
brain.screen.draw_pixel(275, 100)
brain.screen.draw_pixel(250, 125)
brain.screen.draw_pixel(275, 125)

Una captura de pantalla del V5 Brain que muestra una variedad de píxeles que muestran las esquinas de un cuadrado.

draw_line#

draw_line draws a line using the current pen color.

Uso:

brain.screen.draw_line(start_x, start_y, end_x, end_y)

Parámetros

Descripción

start_x

La posición x del inicio de la línea referenciada al origen de la pantalla.

start_y

La posición y del inicio de la línea referenciada al origen de la pantalla.

end_x

La posición x del final de la línea referenciada al origen de la pantalla.

end_y

La posición y del final de la línea referenciada al origen de la pantalla.

# Draw a line from the top left to bottom right of the screen
brain.screen.draw_line(0, 0, 479, 239)

La pantalla muestra una delgada línea diagonal en el centro, desde la esquina superior izquierda hasta la esquina inferior derecha.

draw_rectangle#

draw_rectangle draws a rectangle on the screen using the current pen and fill colors.

Uso:

brain.screen.draw_rectangle(x, y, width, height, color)

Parámetros

Descripción

x

La coordenada x en píxeles de la esquina superior izquierda del rectángulo de 0 a 479.

y

La coordenada y en píxeles de la esquina superior izquierda del rectángulo de 0 a 239.

width

El ancho del rectángulo.

height

La altura del rectángulo.

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# Draw a rectangle on the screen
brain.screen.draw_rectangle(50, 50, 130, 60)

La pantalla del robot muestra un rectángulo con un borde blanco fino en la pantalla.

draw_circle#

draw_circle(x, y, radius, color) draws a circle using the current pen and fill colors.

Uso:

brain.screen.draw_circle(x, y, radius, color)

Parámetros

Descripción

x

La posición x del centro del círculo referenciado al origen de la pantalla.

y

La posición y del centro del círculo referenciada al origen de la pantalla.

radius

El radio del círculo.

color

Optional. A valid color option:

  • Color.RED
  • Color.GREEN
  • Color.BLUE
  • Color.YELLOW
  • Color.ORANGE
  • Color.PURPLE
  • Color.CYAN
  • Color.TRANSPARENT
  • Color.WHITE
# Draw a circle on the screen
brain.screen.draw_circle(120, 120, 40)

La pantalla del robot muestra un círculo con un fino borde blanco dibujado en el centro.

render#

render enables double buffering for the Brain’s screen. Once called, any drawing commands (like text, shapes, or images) will no longer appear immediately for the rest of the project. Instead, updates will only be shown when render is used again. This allows for smoother and more controlled screen updates, but means nothing will be visible until render is used.

Uso:

brain.screen.render()

Parámetros

Descripción

Este método no tiene parámetros.

# Render text after moving
brain.screen.render()
brain.screen.print("Render later...")
drivetrain.drive_for(FORWARD, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.render()

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.

Uso:

brain.screen.set_clip_region(x, y, width, height)

Parámetros

Descripción

x

La posición x de la esquina superior izquierda del rectángulo, referenciada al origen de la pantalla.

y

La posición y de la esquina superior izquierda del rectángulo, referenciada al origen de la pantalla.

width

El ancho del rectángulo.

height

La altura del rectángulo.

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

La pantalla del robot muestra un rectángulo rojo recortado con un borde blanco fino y un texto que dice "CUTOF" encima del rectángulo.

Tocar#

pressing#

pressing returns whether the screen is currently being pressed (touched).

  • True - The screen is being pressed.

  • False - The screen is not being pressed.

Uso:

brain.screen.pressing()

Parámetros

Descripción

Este método no tiene parámetros.

# Change the screen's color after it's pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.GREEN)
brain.screen.draw_rectangle(0, 0, 479, 239)

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

x_position#

x_position returns the X coordinate of the last screen event, press or release as an integer.

Uso:

brain.screen.x_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Display a circle where the screen is pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)

y_position#

y_position returns the Y coordinate of the last screen event, press or release as an integer.

Uso:

brain.screen.y_position()

Parámetros

Descripción

Este método no tiene parámetros.

# Display a circle where the screen is pressed
while not brain.screen.pressing():
    wait(5, MSEC)
brain.screen.set_fill_color(Color.WHITE)
brain.screen.draw_circle(brain.screen.x_position(), brain.screen.y_position(), 20)

Devoluciones de llamadas#

pressed#

pressed registers a function to be called when the Brain’s Screen is pressed.

Uso:

brain.screen.pressed(callback, arg)

Parámetros

Descripción

callback

Una función previamente definida que se ejecuta cuando se presiona la pantalla Cerebro.

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.

def my_function():
  brain.screen.print("Screen pressed")

# Call my_function whenever the Brain screen is pressed
brain.screen.pressed(my_function)

released#

released registers a function to be called when the screen is released (touch removed).

Uso:

brain.screen.released(callback, arg)

Parámetros

Descripción

callback

Una función previamente definida que se ejecuta cuando se libera la pantalla del Cerebro.

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.

def my_function():
  brain.screen.print("Screen released")

# Call my_function whenever the Brain screen is released
brain.screen.released(my_function)