Screen#

Introduction#

The VEX IQ (2nd-gen) Brain screen provides a variety of methods to display information, draw shapes, and control the visual elements of the screen.

For the examples below, the constructed Brain includes access to the Screen methods and will be used in all subsequent examples throughout this API documentation when referring to those methods.

Below is a list of all methods:

Cursor – Methods for text positioning and display

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

Mutators – Methods for setting screen properties

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

Draw – Methods for drawing shapes and graphics

  • 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);

Parameters

Description

value

The text to display on the screen. Use C++ string formatting to print variable.

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

  // Display a message at the starting cursor
  Brain.Screen.print("Hello, Robot!");
}

A screenshot of the VEX IQ Brain screen reads Hello, Robot! in white text on the first line.

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

Parameters

Description

row

The row of the cursor.

col

The column of the 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);
  }
}

A screenshot of the IQ Brain screen reads 23.19 in white text in the upper left corner.

newLine#

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

Usage:
Brain.Screen.newLine();

Parameters

Description

This method has no parameters.

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");
}

A screenshot of the IQ Brain screen reads Line 1 in white text in the upper left corner, and Line 2 directly below it.

clearLine#

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

Usage:
Brain.Screen.clearLine(row, color);

Parameters

Description

row

Optional. The row to clear. The default is the current cursor row.

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

Parameters

Description

This method has no parameters.

column#

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

Usage:
Brain.Screen.column()

Parameters

Description

This method has no parameters.

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

Parameters

Description

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

The text to print on the screen. Use the C++ string formatting to print variable.

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

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

A screenshot of the IQ Brain screen with a number 1 in white text in the upper right quadrant, at the (100, 40) position.

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

Parameter

Description

x

The x-coordinate of the top-left corner of the clip region, given as an integer or float from 0 to 160.

y

The y-coordinate of the top-left corner of the clip region, given as an integer or float from 0 to 108.

width

The width of the clip region in pixels, given as an integer or float from 0 to 160.

height

The height of the clip region in pixels, given as an integer or float from 0 to 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!");
}

A screenshot of the IQ Brain screen with white text near the center of the screen that reads Cut of, with a solid red square directly beneath it, showing what prints in the clip region.

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

Parameters

Description

string

The string to measure.

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

Parameters

Description

string

The string to measure.

Mutators#

clearScreen#

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

Usage:
Brain.Screen.clearScreen();

Parameters

Description

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

Parameter

Description

type

Sets the font to one of the following:

  • mono12
  • mono15
  • mono20
  • mono30
  • mono40
  • mono60
  • prop20
  • prop30
  • prop40
  • prop60
These options are shown below.

A screenshot of the VEX IQ Brain screen with a series of numbers and letters in Mono 12 font. The letter A-Z are on one line, spanning the width of the screen. The lower left corner indicates 26 characters across and 9 rows.
mono12

The same screenshot as the one previous, now with Mono 15 font. The letters A-T are on one line, spanning the width of the screen. The lower left corner indicates 20 characters across and 7 rows.
mono15

The same screenshot as the one previous, now with Mono 20 font. The letters A-P are on one line, spanning the width of the screen. The lower left corner indicates 16 characters across and 5 rows.
mono20

The same screenshot as the one previous, now with Mono 30 font. The numbers 1 through 9 and an extra 0 are on one line, spanning the width of the screen. The lower left corner indicates 3 rows.
mono30

The same screenshot as the one previous, now with Mono 40 font. The numbers 1 through 8 are on the second line, spanning the width of the screen.
mono40

The same screenshot as the one previous, now with Mono 60 font. The screen shows MN 60 in large font, taking up nearly the whole top half of the screen.
mono60

The same screenshot as the one previous, now with Prop 20 font. The letters A-W are on one line, spanning the width of the screen. The lower left corner indicates 26 characters across and 5 rows.
prop20

The same screenshot as the one previous, now with Prop 30 font. The numbers 1-9 are repeated twice on one line, spanning the width of the screen. The lower left corner indicates 18 characters across and 3 rows.
prop30

The same screenshot as the one previous, now with Prop 40 font. The screen reads Prop 40 on the top line and indicates 14 characters and 2 rows on the second.
prop40

The same screenshot as the one previous, now with Prop 60 font. The screen reads PROP 60 in large font, taking up nearly the whole top half of the screen.
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");
}

A screenshot of the IQ Brain screen with white text on two lines in the upper left corner. The first line reads Mono Medium and the second line directly below reads Prop Medium in a smaller font.

setPenWidth#

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

Usage:
Brain.Screen.setPenWidth(value);

Parameter

Description

value

The pen width, given as an integer in pixels in a range from 0 to 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);
}

A screenshot of the IQ Brain screen with two white circles printed on the lower half of the screen. The circle on the left is drawn with a narrower border than the one the right.

setPenColor#

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

Usage:
Brain.Screen.setPenColor(color);

Parameter

Description

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);
}

A screenshot of the IQ Brain screen with two small rectangles drawn on the lower half of the screen. The rectangle on the left is blue, and the one on the right is white.

setFillColor#

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

Usage:
Brain.Screen.setFillColor(color);

Parameter

Description

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);
}

A screenshot of the IQ Brain screen with a bright yellow circle with a thin white border drawn on the left half of the screen.

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

Parameter

Description

x

The new x-coordinate to set as the origin, given as an integer from 0 to 160.

y

The new y-coordinate to set as the origin, given as an integer from 0 to 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);
}

A screenshot of an IQ Brain screen with a while line beginning slightly left of center and extending diagonally downward to the right toward the lower right corner of the screen.

Draw#

drawPixel#

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

Usage:
Brain.Screen.drawPixel(x, y);

Parameter

Description

x

The x-coordinate where the pixel will be drawn, given as an integer from 0 to 160.

y

The y-coordinate where the pixel will be drawn, given as an integer from 0 to 108.

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

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

A screenshot of the IQ Brain screen with a tiny white dot in the center of the screen.

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

Parameter

Description

x1

The starting x-coordinate of the line, given as an integer from 0 to 160.

y1

The starting y-coordinate of the line, given as an integer from 0 to 108.

x2

The ending x-coordinate of the line, given as an integer from 0 to 160.

y2

The ending y-coordinate of the line, given as an integer from 0 to 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);
}

A screenshot of the IQ Brain screen with a white diagonal line drawn from the upper left corner to the lower right corner.

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

Parameter

Description

x

The x-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 160.

y

The y-coordinate of the top-left corner of the rectangle, given as an integer from 0 to 108.

width

The width of the rectangle, given as an integer from 0 to 160.

height

The height of the rectangle, given as an integer from 0 to 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);
}

A screenshot of the IQ Brain screen with a large red rectangle with a thin white border drawn nearly centered on the screen.

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

Parameter

Description

x

The x-coordinate of the center of the circle, given as an integer from 0 to 160.

y

The y-coordinate of the center of the circle, given as an integer from 0 to 160.

radius

The radius of the circle, given as an integer from 0 to 108 pixels.

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);
}

A screenshot of the IQ Brain screen with a solid green circle with a thin white border in the center of the screen.

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();

Parameters

Description

This method has no parameters.

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();
}