Pantalla#

Introducción#

La pantalla cerebral VEX IQ (2.ª generación) ofrece diversos métodos para mostrar información, dibujar formas y controlar los elementos visuales de la pantalla.

This page uses brain as the example Brain name. Replace it with your own configured name as needed.

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

Impresión con cursor: Coloca e imprime 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.

  • get_string_height — Returns the height of a string.

Motadores: Cambian la configuración de la pantalla, los colores y el comportamiento de 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: Añadir gráficos a la pantalla.

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

  • draw_line — Draws a line between two points.

  • draw_rectangle — Draws a rectangle.

  • draw_circle — Draws a circle.

  • set_clip_region — Restricts where drawings and text can appear.

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

Cursor Imprimir#

print#

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

Usage:
brain.screen.print(text, precision, opaque)

Parámetros

Descripción

text

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

precision

Optional. The number of decimal places to display when displaying numbers. This must be written as a keyword argument, ie:precision=3. Default is 2.

opaque

Optional.

  • opaque=True — The background of the text will be filled with the current fill color or black by default.
  • opaque=False (default) — The background of the text will match the screen’s background color.

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

Una captura de pantalla de la pantalla del cerebro VEX IQ muestra "¡Hola, robot!" en texto blanco en la primera línea.

# Display a percentage with 4 decimal 
# places and a blue background
brain.screen.set_fill_color(Color.BLUE)
brain.screen.print((42/100), precision = 4, opaque = True)

set_cursor#

set_cursor sets the cursor at a specific row and column on the Brain’s screen. How many rows and columns can comfortably fit depends on the selected font.

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:
brain.screen.set_cursor(row, column)

Parámetros

Descripción

row

La fila del cursor.

column

La columna del cursor.

# Repeatedly print the Brain's timer at 
# the top left of the screen
while True:
    brain.screen.print(brain.timer.time(SECONDS))
    brain.screen.next_row()
    wait(1, SECONDS)
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)

Una captura de pantalla de la pantalla de IQ Brain muestra 23.19 en texto blanco en la esquina superior izquierda.

next_row#

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

Usage:
brain.screen.next_row()

Parámetros

Descripción

Este método no tiene parámetros.

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

Una captura de pantalla de la pantalla de IQ Brain muestra la Línea 1 en texto blanco en la esquina superior izquierda, y la Línea 2 justo debajo.

clear_row#

clear_row clears a row of drawings and text on the Brain’s screen.

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

Parámetros

Descripción

fila

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. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

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

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

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

row#

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

Usage:
brain.screen.row()

Parámetros

Descripción

Este método no tiene parámetros.

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

Captura de pantalla de IQ Brain con un número 3 blanco impreso en el extremo izquierdo de la pantalla, centrado verticalmente, en la posición de la fila 3, columna 2.

column#

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

Usage:
brain.screen.column()

Parámetros

Descripción

Este método no tiene parámetros.

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

Captura de pantalla de IQ Brain con un número 2 blanco impreso en el extremo izquierdo de la pantalla, centrado verticalmente, en la posición de la fila 3, columna 2.

get_string_width#

get_string_width returns the width of a string in pixels, as it would appear on the Brain’s screen. The width varies depending on the string’s length and the current font.

Usage:
brain.screen.get_string_width(string)

Parámetros

Descripción

string

La cuerda a medir.

get_string_height#

get_string_height returns the height of a string in pixels, as it would appear on the Brain’s screen. The width varies depending on the string’s length and the current font.

Usage:
brain.screen.get_string_height(string)

Parámetros

Descripción

string

La cuerda a medir.

Mutadores#

clear_screen#

clear_screen clears all drawings and text from the Brain’s screen.

Usage:
brain.screen.clear_screen(color)

Parámetros

Descripción

color

Optional. Sets the screen color. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a circle and clear it after 
# 2 seconds
brain.screen.draw_circle(80, 50, 20)
wait(2, SECONDS)
brain.screen.clear_screen()

# Turn the screen red
brain.screen.clear_screen(Color.RED)

Captura de pantalla de IQ Brain con toda el área imprimible en rojo brillante.

set_font#

set_font sets the font used for displaying text on the Brain’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:
brain.screen.set_font(fontname)

Parámetro

Descripción

fontname

Sets the font to one of the following:

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

Captura de pantalla de VEX IQ Brain con una serie de números y letras en fuente Mono 12. Las letras AZ están en una sola línea, abarcando todo el ancho de la pantalla. En la esquina inferior izquierda se indican 26 caracteres de ancho y 9 filas.
MONO12

La misma captura de pantalla que la anterior, ahora con la fuente Mono 15. Las letras AT están en una sola línea, abarcando todo el ancho de la pantalla. En la esquina inferior izquierda se indican 20 caracteres de ancho y 7 filas.
MONO15

La misma captura de pantalla que la anterior, ahora con la fuente Mono 20. Las letras AP están en una sola línea, abarcando todo el ancho de la pantalla. En la esquina inferior izquierda se indican 16 caracteres de ancho y 5 filas.
MONO20

La misma captura de pantalla que la anterior, ahora con la fuente Mono 30. Los números del 1 al 9 y un 0 adicional aparecen en una sola línea, abarcando todo el ancho de la pantalla. La esquina inferior izquierda indica 3 filas.
MONO30

La misma captura de pantalla que la anterior, ahora con la fuente Mono 40. Los números del 1 al 8 están en la segunda línea, abarcando todo el ancho de la pantalla.
MONO40

La misma captura de pantalla que la anterior, ahora con la fuente Mono 60. La pantalla muestra MN 60 en letra grande, ocupando casi toda la mitad superior de la pantalla.
MONO60

La misma captura de pantalla que la anterior, ahora con la fuente de la Propuesta 20. Las letras AW están en una sola línea, abarcando todo el ancho de la pantalla. En la esquina inferior izquierda se indican 26 caracteres de ancho y 5 filas.
PROP20

La misma captura de pantalla que la anterior, ahora con la fuente de la Propuesta 30. Los números del 1 al 9 se repiten dos veces en una línea, abarcando todo el ancho de la pantalla. En la esquina inferior izquierda se indican 18 caracteres de ancho y 3 filas.
PROP30

La misma captura de pantalla que la anterior, ahora con la fuente de la Propuesta 40. En la primera línea se lee "Propuesta 40" y en la segunda se indican 14 caracteres y 2 filas.
PROP40

La misma captura de pantalla que la anterior, ahora con la fuente de la Propuesta 60. En la pantalla se lee PROP 60 en letra grande, ocupando casi toda la mitad superior de la pantalla.
PROP60

# Display two different fonts on 
# two separate lines
brain.screen.set_font(FontType.MONO20)
brain.screen.print("Mono Medium")
brain.screen.next_row()
brain.screen.set_font(FontType.PROP20)
brain.screen.print("Prop Medium")

Captura de pantalla de IQ Brain con texto blanco en dos líneas en la esquina superior izquierda. La primera línea dice Mono Medium y la segunda línea justo debajo dice Prop Medium en una fuente más pequeña.

set_pen_width#

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

Usage:
brain.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 two circles with 
# different pen widths
brain.screen.draw_circle(40, 70, 20)
brain.screen.set_pen_width(5)
brain.screen.draw_circle(100, 70, 20)

Captura de pantalla de IQ Brain con dos círculos blancos impresos en la mitad inferior de la pantalla. El círculo de la izquierda tiene un borde más estrecho que el de la derecha.

set_pen_color#

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

Usage:
brain.screen.set_pen_color(color)

Parámetro

Descripción

color

Optional. Sets the pen color. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw two rectangles with 
# different colors
brain.screen.draw_rectangle(100, 50, 10, 20)
brain.screen.set_pen_color(Color.BLUE)
brain.screen.draw_rectangle(50, 50, 10, 20)

Captura de pantalla de IQ Brain con dos pequeños rectángulos dibujados en la mitad inferior de la pantalla. El rectángulo de la izquierda es azul y el de la derecha es blanco.

set_fill_color#

set_fill_color method sets the fill color used when shapes are drawn.

Usage:
brain.screen.set_fill_color(color)

Parámetro

Descripción

color

Optional. Sets the fill color. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a yellow circle
brain.screen.set_fill_color(Color.YELLOW)
brain.screen.draw_circle(50, 50, 20)

Captura de pantalla de IQ Brain con un círculo amarillo brillante con un borde blanco delgado dibujado en la mitad izquierda de la pantalla.

set_origin#

set_origin sets the origin (0,0) used for drawing or printing on the Brain’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:
brain.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 160.

y

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

# Draw a line with the origin set to (50, 50)
brain.screen.set_origin(50, 50)
brain.screen.draw_line(1, 1, 159, 107)

Captura de pantalla de IQ Brain con una línea blanca que comienza ligeramente a la izquierda del centro y se extiende diagonalmente hacia abajo y a la derecha, hacia la esquina inferior derecha de la pantalla.

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:
brain.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 160.

y

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

# Draw one pixel at the center 
# of the screen
brain.screen.draw_pixel(80, 50)

Captura de pantalla de IQ Brain con un pequeño punto blanco en el centro de la pantalla.

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:
brain.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 de 0 a 160.

y1

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

x2

La coordenada x final de la línea, expresada como un número entero de 0 a 160.

y2

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

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

Captura de pantalla de IQ Brain con una 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:
brain.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 160.

y

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

width

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

height

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

color

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

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a red rectangle on the screen
brain.screen.draw_rectangle(25, 25, 100, 50, Color.RED)

Captura de pantalla de IQ Brain con un gran rectángulo rojo con un borde blanco delgado dibujado casi centrado en 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:
brain.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 160.

y

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

radius

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

color

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

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a green circle on the screen
brain.screen.draw_circle(80, 50, 20, Color.GREEN)

Captura de pantalla de IQ Brain con un círculo verde sólido con un borde blanco delgado en el centro de la pantalla.

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:
brain.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 160.

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

width

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

height

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

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

Captura de pantalla de IQ Brain con texto blanco cerca del centro de la pantalla que dice "Cortar", con un cuadrado rojo sólido justo debajo, que muestra lo que se imprime en la región de recorte.

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.

Usage:
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()