屏幕#

打印()#

print(value, format, ...) 方法使用当前光标位置在屏幕上打印文本。

参数

描述

价值

要打印的文本。

格式

打印变量值时使用的格式说明符。

要使用格式说明符打印的参数变量列表。

**返回:**无。

// Print the number 1 on the Brain's screen at current
// cursor position.
Brain.Screen.print(1);

打印()#

printAt(text, x, y, format, precision, ...) 方法在屏幕上特定的 x 和 y 坐标处打印文本。

参数

描述

价值

要打印的文本。

x

作为关键字参数 (x=) 打印的 x 位置,参考屏幕原点。

y

作为关键字参数 (y=) 打印的 y 位置,参考屏幕原点。

格式

打印变量值时使用的格式说明符。

要使用格式说明符打印的参数变量列表。

**返回:**无。

// Print the number 1 on the Brain's screen at
// position (100, 40).
Brain.Screen.printAt(1, x=100, y=40);

设置光标()#

setCursor(x, y) 方法设置光标位置。行距和列距会考虑所选字体。对于 MONO20 字体,基本单元格大小为 10x20 像素。屏幕左上角为位置 (x=1, y=1)。

参数

描述

x

光标的 x 位置。

y

光标的 y 位置。

**返回:**无。

设置原点()#

setOrigin(x, y) 方法设置 Brain 屏幕上用于绘制图形的原点。绘图函数将 Brain 屏幕的左上角视为原点。此函数可以将原点移动到其他位置,例如 Brain 屏幕的中心。

参数

描述

x

原点相对于左上角的 x 位置。

y

原点相对于左上角的 y 位置。

**返回:**无。

设置字体()#

setFont(fontname) 方法设置在 Brain 屏幕上打印文本所使用的字体类型。

参数

描述

字体名称

有效的 fontType

**返回:**无。

// Set the font type to mono40.
Brain.Screen.setFont(fontType::mono40);

设置笔宽()#

setPenWidth(width) 方法设置用于绘制线条、矩形和圆形的笔宽。

参数

描述

宽度

笔的宽度。

**返回:**无。

// Set the pen width to 5 pixels.
Brain.Screen.setPenWidth(5);

设置笔颜色()#

画笔颜色可以通过两种方式设置:

setPenColor(color) 方法将笔的颜色设置为指定的颜色。

参数

描述

颜色

先前定义的 colorType 对象或十六进制值。

**返回:**无。

// Set pen color red using a Hex value.
Brain.Screen.setPenColor(0xFF0000);

// Set pen color blue using a predefined color.
Brain.Screen.setPenColor(blue);

// Set pen color green using a web string.
Brain.Screen.setPenColor("#00FF00");

setPenColor(hue) 方法使用指定的色调设置笔的颜色。

参数

描述

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

设置填充颜色()#

填充颜色可以通过两种方式设置:

setFillColor(color) 方法使用指定的颜色设置填充颜色。

参数

描述

颜色

先前定义的 colorType 对象或十六进制值。

**返回:**无。

// Set pen color red using a hex value.
Brain.Screen.setFillColor(0xFF0000);

// Set pen color blue using a predefined color.
Brain.Screen.setFillColor(blue);

// Set pen color green using a web string.
Brain.Screen.setFillColor("#00FF00");

setFillColor(hue) 方法使用指定的色调设置填充颜色。

参数

描述

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

柱子()#

column() 方法返回将打印文本的当前列。

**返回:**当前列位置。

排()#

row() 方法返回将打印文本的当前行。

**返回:**当前行位置。

获取字符串宽度()#

getStringWidth(string) 方法获取字符串的宽度(以像素为单位),就像它在 Brain 屏幕上一样。字符串的宽度会根据字符串的长度和字体的大小而变化。

参数

描述

细绳

要测量的字符串。

**返回:**字符串的宽度(整数)。

获取字符串高度()#

getStringHeight(string) 方法获取字符串的高度(以像素为单位),就像它在 Brain 屏幕上一样。字符串的高度会根据字符串的长度和字体的大小而变化。

参数

描述

细绳

要测量的字符串。

**返回:**字符串的高度(整数)。

清除屏幕()#

大脑的屏幕可以通过三种方式清除:

clearScreen() 方法将 Brain 的屏幕清除为默认颜色(黑色)。

**返回:**无。

// Print VEXcode on the Brain's screen.
Brain.Screen.print("VEXcode");

// Clear screen to black.
Brain.Screen.clearScreen();

clearScreen(color) 方法将整个 Brain 的屏幕清除为指定的颜色。

参数

描述

颜色

先前定义的 colorType 对象或十六进制值。

**返回:**无。

// Print VEXcode on the Brain's screen.
Brain.Screen.print("VEXcode");

// Clear screen to blue using a predefined color.
Brain.Screen.clearScreen(blue);

clearScreen(hue) 方法将整个 Brain 的屏幕清除为指定的色调。

参数

描述

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

清除线()#

可以通过四种方式清除大脑屏幕上的线条:

clearLine() 方法清除光标当前所在的行。

**返回:**无。

clearLine(number) 方法清除指定的行。

参数

描述

数字

要清除的行。

**返回:**无。

clearLine(number, color) 方法清除指定的行并将该行设置为指定的颜色。

参数

描述

数字

要清除的行。

颜色

先前定义的 color 对象或十六进制值。

**返回:**无。

clearLine(number, hue) 方法清除指定的行并将该行设置为指定的色调。

参数

描述

数字

要清除的行。

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

新行()#

newLine() 方法将光标移动到下一行。

**返回:**无。

绘制像素()#

drawPixel(x, y) 方法使用当前笔颜色绘制一个像素。

参数

描述

x

绘制像素的 x 位置参考屏幕原点。

y

绘制像素的 y 位置参考屏幕原点。

**返回:**无。

// Draw a red pixel on the Brain's screen.
Brain.Screen.setPenColor(red);
Brain.Screen.drawPixel(10, 10);

绘制线()#

drawLine(x1, y1, x2, y2) 方法使用当前笔颜色绘制一条线。

参数

描述

x1

线的起点相对于屏幕原点的 x 位置。

y1

线的起点相对于屏幕原点的 y 位置。

x2

线尾相对于屏幕原点的 x 位置。

y2

线末端相对于屏幕原点的 y 位置。

**返回:**无。

// Draw a red line on the Brain's screen.
Brain.Screen.setPenColor(red);
Brain.Screen.drawLine(10, 10, 20, 20);

绘制矩形()#

可以用三种方式在 Brain 的屏幕上绘制矩形:

drawRectangle(x, y, width, height) 方法使用当前的画笔和填充颜色在屏幕上绘制一个矩形。

参数

描述

x

矩形左上角相对于屏幕原点的 x 位置。

y

矩形左上角相对于屏幕原点的 y 位置。

宽度

矩形的宽度。

高度

矩形的高度。

**返回:**无。

// Draw a green rectangle on the screen that is
// filled using blue.
Brain.Screen.setPenColor(green);
Brain.Screen.setFillColor(blue);
Brain.Screen.drawRectangle(10, 10, 20, 20);

drawRectangle(x, y, width, height, color) 方法使用当前笔在屏幕上绘制一个矩形,并用指定的颜色填充圆圈。

参数

描述

x

矩形左上角相对于屏幕原点的 x 位置。

y

矩形左上角相对于屏幕原点的 y 位置。

宽度

矩形的宽度。

高度

矩形的高度。

颜色

先前定义的 color 对象或十六进制值。

**返回:**无。

drawRectangle(x, y, width, height, hue) 方法使用当前笔在屏幕上绘制一个矩形,并用指定的色调填充圆圈。

参数

描述

x

矩形左上角相对于屏幕原点的 x 位置。

y

矩形左上角相对于屏幕原点的 y 位置。

宽度

矩形的宽度。

高度

矩形的高度。

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

画圆()#

可以用三种方式在大脑的屏幕上绘制圆圈:

drawCircle(x, y, radius) 方法使用当前的画笔和填充颜色绘制一个圆圈。

参数

描述

x

圆心相对于屏幕原点的 x 位置。

y

圆心相对于屏幕原点的 y 位置。

半径

圆的半径(以像素为单位)。

**返回:**无。

// Draw a green circle on the Brain's screen that is
// filled using blue.
Brain.Screen.setPenColor(green);
Brain.Screen.setFillColor(blue);
Brain.Screen.drawCircle(50, 50, 10);

drawCircle(x, y, radius, color) 方法使用当前笔颜色绘制一个圆圈,并用指定的颜色填充圆圈。

参数

描述

x

圆心相对于屏幕原点的 x 位置。

y

圆心相对于屏幕原点的 y 位置。

半径

圆的半径(以像素为单位)。

颜色

先前定义的 color 对象或十六进制值。

**返回:**无。

drawCircle(x, y, radius, hue) 方法使用当前笔颜色绘制一个圆圈,并用指定的色调填充圆圈。

参数

描述

x

圆心相对于屏幕原点的 x 位置。

y

圆心相对于屏幕原点的 y 位置。

半径

圆的半径(以像素为单位)。

色调

表示颜色色调的整数,范围是 1 - 359。

**返回:**无。

从缓冲区绘制图像()#

drawImageFromBuffer(buffer, x, y, width, height) 方法使用内存缓冲区的内容在屏幕上绘制图像。

参数

描述

缓冲

指向包含原始 32 位每像素图像数据的缓冲区的指针。

x

绘制图像左边缘的 x 坐标。

y

绘制图像顶部边缘的 y 坐标。

宽度

图像的宽度。

高度

图像的高度。

**返回:**一个布尔值,指示图像是否已成功绘制在屏幕上。

从文件绘制图像()#

drawImageFromFile(filename, x, y) 方法从 SD 卡绘制图像。调用该方法时输入的文件名必须位于 SD 卡上。

参数

描述

文件名

图像的文件名。

x

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

y

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

**返回:**无。

// Draw the vex.bmp image on the Brain's screen at
// coordinate 0, 0.
Brain.Screen.drawImageFromFile('vex.bmp', 0, 0);

使成为()#

屏幕可以通过两种方式缓冲:

render() 方法切换到双缓冲或将后缓冲区渲染到 Brain 的屏幕。

**返回:**如果缓冲区成功呈现到屏幕,则返回“true”。

render(bSyncWait, bRunScheduler) 方法切换到双缓冲或将后台缓冲区渲染到 Brain 的屏幕,并可选择在继续之前等待 Vsync 信号并在该过程中运行调度程序。

参数

描述

同步等待

true 使 Brain 等待 Vsync 信号,然后才允许执行后续命令。

运行调度器

true 表示在等待 Brain 屏幕渲染时运行后台任务。默认情况下,此参数为 true

**返回:**如果缓冲区成功呈现到屏幕,则返回“true”。

设置剪辑区域()#

setClipRegion(x, y, width, height) 方法设置用于绘制所提供矩形的剪辑区域。

参数

描述

x

矩形左上角的 x 位置(参考屏幕原点)。

y

矩形左上角的 y 位置(参考屏幕原点)。

宽度

矩形的宽度。

高度

矩形的高度。

**返回:**无。