屏幕#
介绍#
EXP Brain 的屏幕在打印文本时,会设置固定的行数和列数。
默认情况下,打印到大脑的字体是等宽小号,它有7行20列。
大脑的绘图分辨率为 159 x 107 像素。

以下是可用方法列表:
光标打印 – 显示文本并管理打印光标。
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.
设置 – 更改文本和图形的外观。
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.
绘图 – 在大脑屏幕上创建形状、线条和图形。
draw_pixel– Draws a pixel using the current pen color.draw_rectangle– Draws a rectangle on the screen using the current pen and fill colors.draw_circle– Draws a circle using the current pen and fill colors.draw_image_from_file– Draws an image from the SD card.render– Switches drawing to double buffered and renders the Brain’s screen.set_clip_region– Sets the clip region for drawing the supplied rectangle.
光标打印#
print#
print prints text on the screen using the current cursor position.
用法:
brain.screen.print(text, sep, precision)
参数 |
描述 |
|---|---|
|
要打印的文本。 |
|
Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is |
|
Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument( |
brain.screen.print("Hello, Robot!")

# 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='-')
print_at#
print_at prints text at specific x and y coordinates on the screen.
用法:
brain.screen.print_at(text, x, y, sep, precision, opaque)
参数 |
描述 |
|---|---|
|
要打印的文本。 |
|
以关键字参数 (x=) 表示要打印的 x 坐标,参考屏幕原点。 |
|
打印位置的 y 坐标(y=),以屏幕原点为参考。 |
|
Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is |
|
Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument( |
|
Optional. A boolean value indicating whether or not the text should clear background pixels. The default is |
# Print the number 1 on the Brain's screen at position (100, 40).
brain.screen.print_at(1, x=100, y=40)
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.
用法:
brain.screen.set_cursor(row, column)
参数 |
描述 |
|---|---|
|
要将光标设置到的行。 |
|
要将光标设置到的列。 |
# Display text starting at Row 3 Column 10.
brain.screen.set_cursor(3, 10)
brain.screen.print("R3, C10")

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.
用法:
brain.screen.set_origin(x, y)
参数 |
描述 |
|---|---|
|
原点相对于左上角的 x 坐标。 |
|
原点相对于左上角的 y 坐标。 |
next_row#
next_row moves the cursor to the next row.
用法:
brain.screen.next_row()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display two lines of text.
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

clear_row#
clear_row clears a row to a single color.
用法:
brain.screen.clear_row(row)
参数 |
描述 |
|---|---|
|
可选。要清除的行。默认值为当前光标所在行。 |
|
Optional. A valid ColorType, a hex value, or a web string.
|
# 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.
用法:
brain.screen.row()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display the cursor's current row.
brain.screen.set_cursor(3, 10)
brain.screen.print(brain.screen.row())

column#
column returns the current column where text will be printed as an integer.
用法:
brain.screen.column()
参数 |
描述 |
|---|---|
此方法没有参数。 |
# Display the cursor's current column.
brain.screen.set_cursor(3, 10)
brain.screen.print(brain.screen.column())

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.
用法:
brain.screen.get_string_width(string)
参数 |
描述 |
|---|---|
|
待测量的绳子。 |
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.
用法:
brain.screen.get_string_height(string)
参数 |
描述 |
|---|---|
|
待测量的绳子。 |
变异体#
clear_screen#
clear_screen clears the whole Brain’s screen to a single color.
用法:
brain.screen.clear_screen(color)
参数 |
描述 |
|---|---|
|
Optional. A valid ColorType, a hex value, or a web string.
|
# 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.
用法:
brain.screen.set_font(fontname)
参数 |
描述 |
|---|---|
|
The font size (examples below):
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
# Set the font type to MONO40.
brain.screen.set_font(FontType.MONO40)
brain.screen.print("VEX")

set_pen_width#
set_pen_width sets the pen width used for drawing lines, rectangles and circles.
用法:
brain.screen.set_pen_width(width)
参数 |
描述 |
|---|---|
|
笔的宽度。 |
# Draw a rectangle with a pen width of 10.
brain.screen.set_pen_width(10)
brain.screen.draw_rectangle(20, 20, 75, 50)

set_pen_color#
set_pen_color sets the pen color used for drawing lines, rectangles and circles.
用法:
brain.screen.set_pen_color(color)
参数 |
描述 |
|---|---|
|
A valid ColorType, a hex value, or a web string.
|
# Draw a rectangle with orange borders.
brain.screen.set_pen_color(Color.ORANGE)
brain.screen.draw_rectangle(20, 20, 75, 50)

# 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.
用法:
brain.screen.set_fill_color(color)
参数 |
描述 |
|---|---|
|
A valid ColorType, a hex value, or a web string.
|
# Draw a purple rectangle.
brain.screen.set_fill_color(Color.PURPLE)
brain.screen.draw_rectangle(20, 20, 75, 50)

# 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")
画#
draw_pixel#
draw_pixel draws a pixel using the current pen color.
用法:
brain.screen.draw_pixel(x, y)
参数 |
描述 |
|---|---|
|
相对于屏幕原点的 x 坐标,用于绘制像素。 |
|
相对于屏幕原点的 y 坐标,用于绘制像素。 |
# 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)
![]()
draw_line#
draw_line draws a line using the current pen color.
用法:
brain.screen.draw_line(x1, y1, x2, y2)
参数 |
描述 |
|---|---|
|
以屏幕原点为参考的行起始点的 x 坐标。 |
|
该线段起始点相对于屏幕原点的 y 坐标。 |
|
线段末端相对于屏幕原点的 x 坐标。 |
|
线段末端相对于屏幕原点的 y 坐标。 |
# Draw a line from the top left to bottom right of the screen.
brain.screen.draw_line(0, 0, 159, 107)

draw_rectangle#
draw_rectangle draws a rectangle on the screen using the current pen and fill colors.
用法:
brain.screen.draw_rectangle(x, y, width, height, color)
参数 |
描述 |
|---|---|
|
矩形左上角相对于屏幕原点的 x 坐标。 |
|
矩形左上角点的 y 坐标相对于屏幕原点的位置。 |
|
矩形的宽度。 |
|
矩形的高度。 |
|
Optional. A valid ColorType, a hex value, or a web string.
|
# Draw a rectangle on the screen.
brain.screen.draw_rectangle(20, 20, 80, 30)

# 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.
用法:
brain.screen.draw_circle(x, y, radius, color)
参数 |
描述 |
|---|---|
|
圆心相对于屏幕原点的 x 坐标。 |
|
圆心相对于屏幕原点的 y 坐标。 |
|
圆的半径。 |
|
Optional. A valid ColorType, a hex value, or a web string.
|
# Draw a circle on the screen.
brain.screen.draw_circle(80, 50, 20)

# 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.
用法:
brain.screen.draw_image_from_file(filename, x, y)
参数 |
描述 |
|---|---|
|
图片的文件名。 |
|
屏幕上图像左上角的 x 坐标。 |
|
屏幕上图像左上角的 y 坐标。 |
# 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.
Trueif buffer was successfully rendered to the screen.Falseif buffer was not successfully rendered to the screen.
用法:
brain.screen.render()
参数 |
描述 |
|---|---|
此方法没有参数。 |
set_clip_region#
set_clip_region sets the clip region for drawing the supplied rectangle.
用法:
brain.screen.set_clip_region(x, y, width, height)
参数 |
描述 |
|---|---|
|
矩形左上角的 x 坐标,以屏幕原点为参考。 |
|
矩形左上角的 y 坐标,以屏幕原点为参考。 |
|
矩形的宽度。 |
|
矩形的高度。 |









