Pantalla#

Introducción#

La pantalla del EXP Brain tiene una cantidad fija de filas y columnas que se utilizan al imprimir texto en ella.

Por defecto, la fuente para imprimir en el Brain es monoespaciada pequeña, que tiene 7 filas y 20 columnas.

Para dibujar, la resolución del Brain es de 159 x 107 píxeles.

Diagrama de cuadrícula etiquetado de la pantalla del cerebro VEX que muestra filas, columnas, dimensiones de píxeles y coordenadas, con líneas rojas que delimitan la cuadrícula.

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

Impresión con cursor: muestra el texto y gestiona el cursor de impresión.

  • print – Prints text on the screen using the current cursor position.

  • print_at – Prints text at specific x and y coordinates on the screen.

  • set_cursor – Sets the cursor position.

  • set_origin – Sets the origin used for drawing graphics on the Brain’s screen.

  • next_row – Moves the cursor to the next row.

  • clear_row – Clears a row to a single color.

  • row – Returns the current row where text will be printed.

  • column – Returns the current column where text will be printed.

  • get_string_width – Gets the width of a string in pixels as if it was on the Brain’s screen.

  • get_string_height – Gets the height of a string in pixels as if it was on the Brain’s screen.

Ajustes: Cambia la apariencia del texto y los gráficos.

  • clear_screen – Clears the whole Brain’s screen to a single color.

  • set_font – Sets the font type used for printing text on the Brain’s screen.

  • set_pen_width – Sets the pen width used for drawing lines, rectangles and circles.

  • set_pen_color – Sets the pen color used for drawing lines, rectangles and circles.

  • set_fill_color – Sets the fill color used for drawing rectangles and circles.

Dibuja: crea formas, líneas y gráficos en la pantalla del cerebro.

Impresión del cursor#

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 para imprimir.

sep

Optional. A string to inset 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.

brain.screen.print("Hello, Robot!")

Captura de pantalla del EXP Brain que muestra "Hola Robot" impreso en la pantalla.

# Print the number 1 on the Brain's screen at current
# cursor position.
brain.screen.print(1)

# Print the numbers 1, 2, 3 and 4 on the Brain's screen at
# current cursor position separated by a '-'.
brain.screen.print(1, 2, 3, 4, sep='-')

set_cursor#

set_cursor sets the cursor position. The row and column spacing will take into account the selected font. The default cursor position is Row 1, Column 1.

Uso:

brain.screen.set_cursor(row, column)

Parámetros

Descripción

row

La fila donde colocar el cursor.

column

La columna donde se colocará el cursor.

# Display text starting at Row 3 Column 10.
brain.screen.set_cursor(3, 10)
brain.screen.print("R3, C10")

Captura de pantalla del EXP Brain que muestra "R3, C10" impreso en la pantalla.

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 en relación con la esquina superior izquierda.

y

La posición Y del origen con respecto a la esquina superior izquierda.

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.

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

Captura de pantalla del EXP Brain que muestra el texto "3" en la fila 3.

clear_row#

clear_row clears a row to a single color.

Uso:

brain.screen.clear_row(row)

Parámetros

Descripción

row

Opcional. La fila que se va a borrar. Por defecto, se utiliza la fila donde se encuentra el cursor.

color

Optional. A valid ColorType, a hex value, or a web string.

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

# Clear Brain's screen to black.
brain.screen.clear_row()

# Clear Brain's screen to blue using predefined color.
brain.screen.clear_row(2, Color.BLUE)

row#

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

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, 10)
brain.screen.print(brain.screen.row())

Captura de pantalla del EXP Brain que muestra el texto "3" en la fila 3.

column#

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

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(3, 10)
brain.screen.print(brain.screen.column())

Captura de pantalla del EXP Brain que muestra el texto "10" en la columna 10.

get_string_width#

get_string_width gets the width of a string in pixels 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.

Uso:

brain.screen.get_string_width(string)

Parámetros

Descripción

string

La cuerda para medir.

get_string_height#

get_string_height gets the height of a string 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.

Uso:

brain.screen.get_string_height(string)

Parámetros

Descripción

string

La cuerda para medir.

Mutadores#

clear_screen#

clear_screen clears the whole Brain’s screen to a single color.

Uso:

brain.screen.clear_screen(color)

Parámetros

Descripción

color

Optional. A valid ColorType, a hex value, or a web string.

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

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

# Clear screen to black.
brain.screen.clear_screen()

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

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

set_font#

set_font sets the font type used for printing text on the Brain’s screen.

Uso:

brain.screen.set_font(fontname)

Parámetros

Descripción

fontname

The font size (examples below):

  • MONO12
  • MONO15
  • MONO20
  • MONO30
  • MONO40
  • MONO60
  • PROP20
  • PROP30
  • PROP40
  • PROP60
Note: Extra small and small sizes are not available for proportional fonts.

La pantalla del Cerebro muestra números y letras impresos en fuente MONO 12. Muestra las letras de la A a la Z y todos los números. En la parte inferior de la pantalla, indica 9 filas y 26 columnas.
MONO12

La pantalla del Cerebro muestra números y letras impresos en fuente MONO 15. Muestra desde la A hasta la T y todos los números. En la parte inferior de la pantalla, indica 7 filas, 22 columnas.
MONO15

La pantalla del Cerebro muestra números y letras impresos en fuente MONO 20. Muestra las letras de la A a la P y todos los números. En la parte inferior de la pantalla, indica 5 filas y 16 columnas.
MONO20

La pantalla del Cerebro muestra números y letras impresos con fuente MONO 30. Muestra de la A a la J. En la parte inferior de la pantalla, dice R:3 C:10.
MONO30

La pantalla del Cerebro mostraba números y letras impresos con una fuente MONO 40 de tamaño. En la parte inferior de la pantalla, se leía R:2 C:8.
MONO40

El Cerebro imprime números y letras en la pantalla con una fuente MONO 60. Solo se muestra MON60.
MONO60

La pantalla del Cerebro muestra números y letras impresos con la fuente PROP 20. Muestra las letras de la A a la W y todos los números. En la parte inferior de la pantalla, se indica 5 filas, 16 columnas.
PROP20

La pantalla del Cerebro muestra números y letras impresos con una fuente de tamaño PROP 30. Muestra de la A a la P. En la parte inferior de la pantalla, dice R:3 C:10.
PROP30

La pantalla del Cerebro mostraba números y letras impresos con una fuente de tamaño PROP 40. En la parte inferior de la pantalla, se leía R:2 C:8.
PROP40

El cerebro imprime números y letras en pantalla con fuente PROP 60. Solo se muestra PROP60.
PROP60

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

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

set_pen_width#

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

Uso:

brain.screen.set_pen_width(width)

Parámetros

Descripción

width

El ancho del bolígrafo.

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

Captura de pantalla del cerebro EXP 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 ColorType, a hex value, or a web string.

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

# Draw a rectangle with orange borders. 
brain.screen.set_pen_color(Color.ORANGE)
brain.screen.draw_rectangle(20, 20, 75, 50)

Captura de pantalla del cerebro EXP que muestra un rectángulo con bordes naranjas.

# Set pen color red using a hex value.
brain.screen.set_pen_color(0xFF0000)

# Set pen color blue using predefined color.
brain.screen.set_pen_color(Color.BLUE)

# Set pen color green using web string.
brain.screen.set_pen_color("#00FF00")

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 ColorType, a hex value, or a web string.

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

# Draw a purple rectangle.
brain.screen.set_fill_color(Color.PURPLE)
brain.screen.draw_rectangle(20, 20, 75, 50)

Captura de pantalla del Cerebro EXP que muestra un rectángulo relleno de color púrpura.

# Set pen color red using a hex value.
brain.screen.set_fill_color(0xFF0000)

# Set pen color blue using predefined color.
brain.screen.set_fill_color(Color.BLUE)

# Set pen color green using web string.
brain.screen.set_fill_color("#00FF00")

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 con respecto al origen de la pantalla.

y

La posición Y para dibujar el píxel con respecto al origen de la pantalla.

# Draw the pixels marking the corners of a square.
brain.screen.draw_pixel(50, 50)
brain.screen.draw_pixel(50, 75)
brain.screen.draw_pixel(75, 50)
brain.screen.draw_pixel(75, 75)

Captura de pantalla del cerebro EXP 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(x1, y1, x2, y2)

Parámetros

Descripción

x1

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

y1

La posición Y del inicio de la línea con respecto al origen de la pantalla.

x2

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

y2

La posición en el eje y del extremo de la línea con respecto al origen de la pantalla.

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

La pantalla del Cerebro 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 posición x de la esquina superior izquierda del rectángulo con respecto al origen de la pantalla.

y

La posición Y de la esquina superior izquierda del rectángulo con respecto al origen de la pantalla.

width

El ancho del rectángulo.

height

La altura del rectángulo.

color

Optional. A valid ColorType, a hex value, or a web string.

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

# Draw a rectangle on the screen.
brain.screen.draw_rectangle(20, 20, 80, 30)

La pantalla del Cerebro muestra un rectángulo con un fino borde blanco.

# Draw a green rectangle on the screen that is filled using blue.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.set_fill_color(Color.BLUE)
brain.screen.draw_rectangle(10, 10, 20, 20)

# Draw a green rectangle on the screen that is filled using red.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.draw_rectangle(50, 50, 20, 20, Color.RED)

draw_circle#

draw_circle 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 con respecto al origen de la pantalla.

y

La posición Y del centro del círculo con respecto al origen de la pantalla.

radius

El radio del círculo.

color

Optional. A valid ColorType, a hex value, or a web string.

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

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

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

# Draw a green circle on the Brain's screen that is filled using blue.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.set_fill_color(Color.BLUE)
brain.screen.draw_circle(50, 50, 10)

# Draw a green circle on the Brain's screen that is filled using red.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.draw_circle(100, 50, 10, Color.RED)

draw_image_from_file#

draw_image_from_file draws an image from the SD card. The filename you put when calling the method must be located on the SD card.

Uso:

brain.screen.draw_image_from_file(filename, x, y)

Parámetros

Descripción

filename

El nombre del archivo de la imagen.

x

La coordenada x de la esquina superior izquierda de la imagen en la pantalla.

y

La coordenada y de la esquina superior izquierda de la imagen en la pantalla.

# Draw the vex.bmp image on the Brain's screen at coordinate 0, 0.
brain.screen.draw_image_from_file('vex.bmp', 0, 0)

render#

render switches drawing to double buffered and renders the Brain’s screen. Once called, further drawing will not appear on the Brain’s screen until the next time render is called.

  • True if buffer was successfully rendered to the screen.

  • False if buffer was not successfully rendered to the screen.

Uso:

brain.screen.render()

Parámetros

Descripción

Este método no tiene parámetros.

set_clip_region#

set_clip_region sets the clip region for drawing the supplied rectangle.

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, con respecto al origen de la pantalla.

y

La posición Y de la esquina superior izquierda del rectángulo, con respecto al origen de la pantalla.

width

El ancho del rectángulo.

height

La altura del rectángulo.