Pantalla#

Introducción#

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

Para los ejemplos siguientes, el cerebro construido incluye acceso a los métodos de Pantalla y se utilizará en todos los ejemplos posteriores en esta documentación de API cuando se haga referencia a esos métodos.

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

Cursor – Métodos para posicionar y visualizar texto

  • print – Prints text at the current cursor position.

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

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

  • clearLine – Clears a row of text.

  • row – Returns the current cursor row.

  • column – Returns the current cursor column.

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

  • setClipRegion – Restricts where drawings and text can appear.

  • getStringWidth – Returns the width of a string.

  • getStringHeight – Returns the height of a string.

Mutadores: métodos para configurar las propiedades de la pantalla

  • clearScreen – Clears the screen of all drawings and text.

  • setFont – Sets the font for printed text.

  • setPenWidth – Sets the thickness for drawn shapes and lines.

  • setPenColor – Sets the color for outlines and text.

  • setFillColor – Sets the fill color for shapes and backgrounds.

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

Dibujar – Métodos para dibujar formas y gráficos

  • drawPixel – Draws a pixel at a specific x and y position.

  • drawLine – Draws a line between two points.

  • drawRectangle – Draws a rectangle.

  • drawCircle – Draws a circle.

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

Cursor#

print#

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

Usage:
Brain.Screen.print(value);

Parámetros

Descripción

value

El texto que se mostrará en pantalla. Use formato de cadena de C++ para imprimir la variable.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display a message at the starting cursor
  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.

setCursor#

setCursor 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, setCursor positions the cursor based on row and column size, not font style. The font size can be adjusted using setFont.

Usage:
Brain.Screen.setCursor(row, col);

Parámetros

Descripción

row

La fila del cursor.

col

La columna del cursor.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Repeatedly print the Brain timer at top-left
  while (true) {
    Brain.Screen.print("%d", Brain.Timer.time(seconds));
    Brain.Screen.newLine();
    wait(1, seconds);
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
  }
}

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

newLine#

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

Usage:
Brain.Screen.newLine();

Parámetros

Descripción

Este método no tiene parámetros.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display two lines of text
  Brain.Screen.print("Line 1");
  Brain.Screen.newLine();
  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.

clearLine#

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

Usage:
Brain.Screen.clearLine(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

Optional. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display text on two rows
  Brain.Screen.print("This text stays");
  Brain.Screen.newLine();
  Brain.Screen.print("This disappears");

  // Wait 3 seconds before clearing row 2
  wait(3, seconds);
  Brain.Screen.clearLine(2);
}

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.

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.

printAt#

printAt displays text on the Brain’s screen at a specified x and y-coordinate (in pixels) with the current font and origin. This method disregards the current cursor position.

Usage:
Brain.Screen.printAt(x, y, value);

Parámetros

Descripción

x

The x position to print at as a keyword argument, ie: x=, referenced to the screen origin.

y

The y position to print at as a keyword argument, ie: y=, referenced to the screen origin.

value

El texto que se imprimirá en pantalla. Utilice el formato de cadena de C++ para imprimir la variable.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Print the number 1 at pixel (100, 40)
  Brain.Screen.printAt(100, 40, "1");
}

Captura de pantalla de IQ Brain con el número 1 en texto blanco en el cuadrante superior derecho, en la posición (100, 40).

setClipRegion#

setClipRegion 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.setClipRegion(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.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Restrict text and drawings to a specific region
  Brain.Screen.setClipRegion(0, 0, 120, 120);
  Brain.Screen.drawRectangle(60, 60, 100, 100, red);
  Brain.Screen.printAt(60, 60, "Cut off!");
}

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.

getStringWidth#

getStringWidth 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.getStringWidth(string);

Parámetros

Descripción

string

La cuerda a medir.

getStringHeight#

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.getStringHeight(string);

Parámetros

Descripción

string

La cuerda a medir.

Mutadores#

clearScreen#

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

Usage:
Brain.Screen.clearScreen();

Parámetros

Descripción

color

Optional. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a circle and clear it after 2 seconds
  Brain.Screen.drawCircle(80, 50, 20);
  wait(2, seconds);
  Brain.Screen.clearScreen();
}

setFont#

setFont sets the font used for displaying text on the Brain’s screen. This font will apply to all text printed with print or printAt. The default font at the start of a project is mono20.

Usage:
Brain.Screen.setFont(type);

Parámetro

Descripción

type

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 línea, abarcando todo el ancho de la pantalla. La esquina inferior izquierda indica 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 línea, abarcando todo el ancho de la pantalla. La esquina inferior izquierda indica 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 línea, abarcando todo el ancho de la pantalla. La esquina inferior izquierda indica 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 están en una 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 fuente grande, ocupando casi toda la mitad superior de la pantalla.
mono60

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

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

La misma captura de pantalla que la anterior, ahora con la fuente Prop 40. La pantalla muestra Prop 40 en la primera línea e indica 14 caracteres y 2 filas en la segunda.
prop40

La misma captura de pantalla que la anterior, ahora con la fuente Prop 60. La pantalla muestra PROP 60 en una fuente grande, ocupando casi toda la mitad superior de la pantalla.
prop60

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Display two different fonts on two lines
  Brain.Screen.setFont(mono20);
  Brain.Screen.print("Mono Medium");
  Brain.Screen.newLine();
  Brain.Screen.setFont(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.

setPenWidth#

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

Usage:
Brain.Screen.setPenWidth(value);

Parámetro

Descripción

value

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

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw two circles with different pen widths
  Brain.Screen.drawCircle(40, 70, 20);
  Brain.Screen.setPenWidth(5);
  Brain.Screen.drawCircle(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.

setPenColor#

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

Usage:
Brain.Screen.setPenColor(color);

Parámetro

Descripción

color

Optional. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw two rectangles with different colors
  Brain.Screen.drawRectangle(100, 50, 10, 20);
  Brain.Screen.setPenColor(blue);
  Brain.Screen.drawRectangle(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.

setFillColor#

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

Usage:
Brain.Screen.setFillColor(color);

Parámetro

Descripción

color

Optional. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a yellow circle
  Brain.Screen.setFillColor(yellow);
  Brain.Screen.drawCircle(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.

setOrigin#

setOrigin 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.setOrigin(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.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a line with the origin set to (50, 50)
  Brain.Screen.setOrigin(50, 50);
  Brain.Screen.drawLine(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#

drawPixel#

drawPixel draws a pixel at the specified (x, y) screen coordinate with the current pen color.

Usage:
Brain.Screen.drawPixel(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.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw one pixel at the center of the screen
  Brain.Screen.drawPixel(80, 50);
}

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

drawLine#

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

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

Usage:
Brain.Screen.drawLine(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.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a line from top-left to bottom-right
  Brain.Screen.drawLine(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.

drawRectangle#

drawRectangle 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 and pen color. The interior is filled with the current fill color.

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

Usage:
Brain.Screen.drawRectangle(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. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a red rectangle on the screen
  Brain.Screen.drawRectangle(25, 25, 100, 50, red);
}

Captura de pantalla de IQ Brain con un gran rectángulo rojo con un borde blanco delgado dibujado casi centrado en la pantalla.

drawCircle#

drawCircle 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 and pen color. The interior is filled with the current fill color.

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

Usage:
Brain.Screen.drawCircle(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. Sets the pen color. Options include:

  • black
  • blue
  • blue_green
  • blue_violet
  • cyan
  • green
  • orange
  • purple
  • red
  • red_orange
  • red_violet
  • violet
  • white
  • yellow
  • yellow_green
  • yellow_orange
You can also specify a custom color.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Draw a green circle on the screen
  Brain.Screen.drawCircle(80, 50, 20, 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.

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.

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Render text after moving
  Brain.Screen.render();
  Brain.Screen.print("Render later...");
  Drivetrain.driveFor(forward, 100, mm);
  Drivetrain.turnFor(right, 90, degrees);
  Brain.Screen.render();
}