屏幕#

介绍#

屏幕方法控制 EXP Brain 如何在其屏幕上显示文本、数字和图形。

默认情况下,打印到大脑的字体是等宽小号,它有7行20列。

大脑的绘图分辨率为 159 x 107 像素。

VEX Brain 屏幕的带标签网格图,显示了行、列、像素尺寸和坐标,并用红线勾勒出网格轮廓。

以下是可用方法列表:

光标打印 – 显示文本并管理打印光标。

  • print – 在当前光标位置打印文本、数字或变量值。

  • print_at – 在指定的 x 和 y 坐标处打印文本、数字或变量值。

  • set_cursor – 将光标移动到指定的行和列。

  • set_origin – 设置用于基于坐标的打印和绘图的原点。

  • next_row – 将光标移动到下一行。

  • clear_row – 清除一行文本。

  • row – 返回要打印文本的行。

  • column – 返回要打印文本的列。

  • get_string_width – 使用当前字体返回字符串的像素宽度。

  • get_string_height – 使用当前字体返回字符串的像素高度。

修改器 – 更改屏幕设置、颜色和绘制行为。

  • clear_screen – 清除大脑屏幕上的所有图形和文本。

  • set_font – 设置大脑屏幕上打印文本所用的字体类型。

  • set_pen_width – 设置绘制的线条和形状轮廓的粗细。

  • set_pen_color – 设置文本、像素、线条和形状轮廓的颜色。

  • set_fill_color – 设置绘制形状和打印文本背景的填充颜色。

绘图 – 在大脑屏幕上创建形状、线条和图形。

光标打印#

print#

print 在 Brain 屏幕上以当前光标位置和字体打印文本、数字或变量值。

用法:

brain.screen.print(text, sep, precision)

参数

描述

text

要打印的文本、数字或变量值。

sep

可选。要在值之间插入的字符串。必须将其写成关键字参数(sep=)。默认值为 “”。

precision

可选。打印简单数字时显示的小数位数。必须以关键字参数的形式指定(precision=)。默认值为 2。

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

EXP Brain 的屏幕截图,显示屏幕上打印着“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='-')

set_cursor#

set_cursor moves the cursor to a specific row and column on the Brain screen. The next print call will start printing at that location. 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)

参数

描述

row

要将光标移动到的行。

column

要将光标移动到的列。

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

EXP Brain 的屏幕截图,显示屏幕上打印着“R3,C10”。

set_origin#

set_origin 设置 Brain 屏幕上用于绘图和基于坐标的打印的原点。默认情况下,原点位于屏幕左上角。

用法:

brain.screen.set_origin(x, y)

参数

描述

x

原点相对于左上角的 x 坐标,范围从 0 到 159。

y

原点相对于左上角的 y 坐标,范围从 0 到 107。

next_row#

next_row 将光标移动到 Brain 屏幕上下一行的第 1 列。

用法:

brain.screen.next_row()

参数

描述

此方法没有参数。

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

EXP Brain 的屏幕截图,显示第 3 行的文本“3”。

clear_row#

clear_row 清除大脑屏幕上的一行文本。

用法:

brain.screen.clear_row(row)

参数

描述

row

可选。要清除的行。默认值为当前光标所在行。

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 条返回将以整数形式打印文本的行。

用法:

brain.screen.row()

参数

描述

此方法没有参数。

# Display the cursor's current row.
brain.screen.set_cursor(3, 10)
brain.screen.print(brain.screen.row())

EXP Brain 的屏幕截图,显示第 3 行的文本“3”。

column#

column 返回文本将以整数形式打印的列。

用法:

brain.screen.column()

参数

描述

此方法没有参数。

# Display the cursor's current column.
brain.screen.set_cursor(3, 10)
brain.screen.print(brain.screen.column())

EXP Brain 的屏幕截图,显示第 10 列的文本“10”。

get_string_width#

get_string_width 返回字符串的宽度(以像素为单位),以整数形式表示,使用当前的 font。

用法:

brain.screen.get_string_width(string)

参数

描述

string

待测量的绳子。

get_string_height#

get_string_height 返回字符串的高度(以像素为单位),使用当前的 font。

用法:

brain.screen.get_string_height(string)

参数

描述

string

待测量的绳子。

变异体#

clear_screen#

clear_screen 清除大脑屏幕上的所有图形和文本。

用法:

brain.screen.clear_screen(color)

参数

描述

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 设置用于在大脑屏幕上显示文本的字体。此字体将应用于此方法运行后打印的所有文本。

用法:

brain.screen.set_font(fontname)

参数

描述

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.

大脑的屏幕以 MONO 12 字体显示数字和字母。它显示了 A 到 Z 以及所有数字。屏幕底部显示 9 行,26 列。
MONO12

大脑的屏幕以 MONO 15 字体显示数字和字母。它显示了 A 到 T 以及所有数字。屏幕底部显示“7 行,22 列”。
MONO15

大脑屏幕以 MONO 20 字体显示数字和字母。显示 A 到 P 以及所有数字。屏幕底部显示 5 行 16 列。
MONO20

大脑的屏幕以 MONO 30 字体显示数字和字母,字体大小为 A 到 J。屏幕底部显示 R:3 C:10。
MONO30

大脑的屏幕以 MONO 40 字体印刷数字和字母。屏幕底部显示 R:2 C:8。
MONO40

大脑的丝网印刷数字和字母,字体大小为 MONO 60。仅显示 MON60。
MONO60

大脑屏幕以 PROP 20 字体大小显示数字和字母。显示 A 到 W 以及所有数字。屏幕底部显示 5 行 16 列。
PROP20

大脑屏幕以 PROP 30 字体大小显示数字和字母。显示 A 到 P。屏幕底部显示 R:3 C:10。
PROP30

大脑屏幕以 PROP 40 字体大小显示数字和字母。屏幕底部显示 R:2 C:8。
PROP40

大脑上的丝网印刷数字和字母,字体大小为 PROP 60。仅显示 PROP60。
PROP60

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

EXP Brain 的屏幕截图,显示“VEX”字样的字体比默认字体更大。

set_pen_width#

set_pen_width 设置绘制线条和形状轮廓的粗细。

用法:

brain.screen.set_pen_width(width)

参数

描述

width

笔的宽度,以像素为单位,范围从 0 到 32。

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

EXP Brain 的屏幕截图,显示一个带有粗边框的矩形。

set_pen_color#

set_pen_color 设置文本、像素、线条和形状轮廓的颜色。

用法:

brain.screen.set_pen_color(color)

参数

描述

color

The pen and font color to use. This can be 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)

EXP Brain 的屏幕截图,显示一个带有橙色边框的矩形。

# 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 设置用于绘制矩形和圆形的填充颜色。

用法:

brain.screen.set_fill_color(color)

参数

描述

color

The fill color to use. This can be 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)

EXP Brain 的屏幕截图,显示一个填充紫色的矩形。

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

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

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

画#

draw_pixel#

draw_pixel 使用当前 笔颜色 在选定的 x 和 y 坐标处绘制一个像素。

用法:

brain.screen.draw_pixel(x, y)

参数

描述

x

绘制像素的 x 坐标,范围从 0 到 159,以屏幕原点为参考。

y

绘制像素的 y 坐标,范围从 0 到 107,以屏幕原点为参考。

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

EXP Brain 的屏幕截图,显示了构成正方形各个角点的像素组合。

draw_line#

draw_line 使用当前的 笔宽 和 笔颜色 从第一个屏幕坐标 (x1, y1) 到第二个屏幕坐标 (x2, y2) 绘制一条线。

用法:

brain.screen.draw_line(x1, y1, x2, y2)

参数

描述

x1

行首的 x 坐标(以像素为单位),范围从 0 到 159,参考屏幕原点。

y1

行首的 y 坐标(以像素为单位),范围从 0 到 107,参考屏幕原点。

x2

行尾的 x 坐标(以像素为单位),范围从 0 到 159,参考屏幕原点。

y2

行尾的 y 坐标(以像素为单位),范围从 0 到 107,参考屏幕原点。

# 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 使用当前的 笔宽、笔颜色 和 填充颜色 绘制矩形,除非使用了可选的 color 参数。

用法:

brain.screen.draw_rectangle(x, y, width, height, color)

参数

描述

x

矩形左上角的 x 坐标(以像素为单位),范围从 0 到 159,参考屏幕原点。

y

矩形左上角的 y 坐标(以像素为单位),范围从 0 到 107,参考屏幕原点。

width

矩形的宽度。

height

矩形的高度。

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)

大脑屏幕上显示一个带有细白边框的矩形。

# 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 使用当前的 笔宽、笔颜色 和 填充颜色 绘制一个圆,除非使用了可选的 color 参数。

用法:

brain.screen.draw_circle(x, y, radius, color)

参数

描述

x

圆心的 x 坐标(以像素为单位),范围从 0 到 159,参考屏幕原点。

y

圆心的 y 坐标(以像素为单位),范围从 0 到 107,参考屏幕原点。

radius

圆的半径。

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)

大脑屏幕上显示一个中心画有细白边的圆圈。

# 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 从 SD 卡绘制图像。调用此方法时指定的文件名必须位于 SD 卡上。

用法:

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

参数

描述

filename

图片的文件名。

x

屏幕上图像左上角的 x 坐标。

y

屏幕上图像左上角的 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 将绘制方式切换到双缓冲,并渲染大脑屏幕。调用此函数后,在下次调用 render 之前,大脑屏幕上不会显示任何新的绘制内容。

  • True 表示缓冲区已成功渲染到屏幕。

  • False 如果缓冲区未成功渲染到屏幕上。

用法:

brain.screen.render()

参数

描述

此方法没有参数。

set_clip_region#

set_clip_region 定义了屏幕上的一个矩形区域,所有图形和文本都将限制在该区域内。该区域之外的任何内容都不会显示。

用法:

brain.screen.set_clip_region(x, y, width, height)

参数

描述

x

矩形左上角的 x 坐标,以屏幕原点为参考。

y

矩形左上角的 y 坐标,以屏幕原点为参考。

width

矩形的宽度。

height

矩形的高度。