屏幕#

介绍#

屏幕模块控制 V5 大脑的触摸屏,使你的机器人能够显示文本、数字和图形,并响应触摸输入。

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

对于绘画而言,大脑的分辨率为 479 x 239 像素。

The V5 Brain screen with red grid lines showing the layout of 12 rows and 48 columns in total. The pixel dimensions are 479 wide by 239 tall. The upper left corner begins at (0,0) pixels and row 1, column 1, while the lower right corner ends at (479, 239) pixels and row 12, column 48.

以下是可用模块列表:

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

设置 – 更改文本和图形的外观。

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

触摸 – 检测大脑屏幕上的触摸输入。

光标打印#

将光标设置到屏幕上的行列#

使用“将光标设置到屏幕上的行和列”模块时,光标会放置在屏幕上的特定行和列。可舒适显示的行数和列数取决于所选字体。使用默认的等宽中等字体,最多可以清晰显示 8 行和 13 列。超出此范围的文本可能会被截断或难以阅读。

等宽字体的所有字符宽度相同,因此文本位置保持一致。相比之下,比例字体的字符宽度各不相同,因此有些字母比其他字母占用更多空间。但是,无论使用哪种字体,“设置光标到行/列”代码块都会根据行和列的大小来定位光标,而#set-font-on-screen根据字体样式。可以使用“设置屏幕上的字体”代码块来调整字体大小。

设置光标堆栈块#
在屏幕上设定光标至 [1] 行 [1] 列

参数

描述

光标所在的行。

柱子

光标所在的列。

例子

启动时,将光标移动到屏幕上的第 3 行第 2 列,并打印“第 3 行,第 2 列”。#
当开始
[Display text starting at Row 3 Column 12.]
在屏幕上设定光标至 [3] 行 [12] 列
在屏幕上打印 [Row 3, Column 12]▶

A screenshot of the V5 Brain showing Row 3 Column 12 printed in the upper portion near the center of screen, at that position.

将光标移至屏幕上的下一行#

将光标设置到屏幕上的下一行 代码块会将光标移动到机器人屏幕上下一行的第 1 列。

将光标设置到下一行堆栈块#
在屏幕上设定光标至下一行

参数

描述

此代码块没有参数。

例子

启动时,屏幕上会打印“第 1 行”,将光标移动到下一行,然后打印“第 2 行”。#
当开始
[Display two lines of text.]
在屏幕上打印 [Line 1]▶
在屏幕上设定光标至下一行
在屏幕上打印 [Line 2]▶

A screenshot of the V5 Brain screen showing two lines of white text in the upper left corner. The top line reads Line 1, and the second line directly below it reads Line 2.

屏幕上的清除行#

清除屏幕上的行 模块会清除机器人屏幕上的一行文本。

清除行堆叠块#
清除屏幕第 [1] 行

参数

描述

要清除的行号。

例子

启动后,文本会打印在两行上。第一行会一直显示,而第二行会在 3 秒后消失。#
当开始
[Only keep the text on row 1.]
在屏幕上打印 [This text stays]▶
在屏幕上设定光标至下一行
在屏幕上打印 [This text disappears]▶
等待 [3] 秒
清除屏幕第 [2] 行

屏幕光标列#

屏幕光标列 块返回文本将打印在的列号,以整数形式表示。

屏幕光标列报告块#
(屏幕光标列数)

参数

描述

此代码块没有参数。

例子

启动时,将光标移动到屏幕上的第 3 行第 2 列,并打印当前光标所在的列号。#
当开始
[Display the cursor's current column.]
在屏幕上设定光标至 [3] 行 [15] 列
在屏幕上打印 (屏幕光标列数)▶

A screenshot of the V5 Brain screen showing the text 15 in white in the upper left quadrant of the screen, at the row 3 column 15 position.

屏幕光标行#

屏幕光标行 块返回文本将打印到的行号(以整数形式)。

屏幕光标行报告块#
(屏幕光标行数)

参数

描述

此代码块没有参数。

例子

启动时,将光标移动到屏幕上的第 6 行第 2 列,并打印当前光标所在的行号。#
当开始
[Display the cursor's current row.]
在屏幕上设定光标至 [3] 行 [2] 列
在屏幕上打印 (屏幕光标行数)▶

A screenshot of the V5 Brain screen showing the text 3 in white in the upper left quadrant of the screen, at the row 3 column 2 position.

设置#

清晰屏幕#

清除屏幕 模块会清除机器人屏幕上的所有图形和文本。

清除屏幕阻挡#
清屏

参数

描述

此代码块没有参数。

例子

启动时,绘制一个以 (120,120) 为圆心、半径为 40 像素的圆。2 秒后,屏幕清空。#
当开始
[Draw a circle, and clear it after 2 seconds.]
在屏幕 [120] [120] [40] 上画圆形
等待 [2] 秒
清屏

设置屏幕上的字体#

“设置屏幕字体”模块用于设置机器人屏幕上显示文本的字体和字号。此字体将应用于之后所有打印的文本。

设置字体堆栈块#
设定屏幕字体为 [等宽字体 v] [中 v]

参数

描述

风格

字体样式:

  • 等宽字体
  • 等宽字体

尺寸

字体大小(示例如下):

  • 特小
  • 特大
  • 超大
注意: 比例字体不提供特小和小尺寸。

A screenshot of the V5 Brain screen with numbers and letters printed in white in the upper left corner in MONO 12 font. It shows A-Z on one line, across about a quarter of the width of screen. In the bottom left corner it reads 80 columns and 20 rows.
monospaced extra small

The same image as the one previous, with Mono 15 font. It shows A-Z on one line, across nearly half width of the screen. In the bottom left corner it reads 68 columns and 16 rows.
monospaced small

The same image as the one previous, with Mono 20 font. It shows A-Z on one line, across nearly two thirds of the width of the screen. In the bottom left corner it reads 48 columns and 12 rows.
monospaced medium

The same image as the one previous, with Mono 30 font. It shows A-Z on one line, across nearly the whole width of the screen. In the bottom left corner it reads 32 columns and 8 rows.
monospaced large

The same image as the one previous, with Mono 40 font. It shows A-X on one line, spanning the width the screen. In the bottom left corner it reads 24 columns and 6 rows.
monospaced extra large

The same image as the one previous, with Mono 60 font. It shows A-P on one line, spanning the width the screen. On the bottom it reads 16 columns and 4 rows.
monospaced super large

The same image as the one previous, with Prop 20 font. It shows A-Z on one line, across nearly two thirds of the width of the screen. In the bottom left corner it reads 48 columns and 12 rows.
proportional medium

The same image as the one previous, with Prop 30 font. It shows A-Z on one line, spanning nearly the width of the screen. In the bottom left corner it reads 32 columns and 8 rows.
proportional large

The same image as the one previous, with Prop 40 font. It shows A-U on one line, spanning the width of the screen. In the bottom left corner it reads 24 columns and 6 rows.
proportional extra large

The same image as the one previous, with Prop 60 font. It shows A-N on one line, spanning the width of the screen. On the bottom it reads 15 columns and 4 rows.
proportional super large

例子

启动时,将字体设置为“等宽特大号”,并在屏幕上打印“VEX”。#
当开始
[Display text using a larger font]
设定屏幕字体为 [等宽字体 v] [特大 v]
在屏幕上打印 [VEX]▶

A screenshot of the V5 Brain screen showing the text "VEX" in larger font than the default in the upper left corner.

设置屏幕打印精度#

“设置屏幕打印精度”模块用于设置机器人屏幕上显示数字的精度格式。此打印精度将应用于之后打印的所有数字。

设置打印精度堆栈块#
在屏幕上设定打印精度为 [0.1 v]

参数

描述

精确

设置打印精度为:

  • 1
  • 0.1
  • 0.01
  • 0.001
  • 所有数字

例子

启动时,将打印精度设置为小数点后两位,并在屏幕上将 1/3 打印为 0.33。#
当开始
[Print 1/3 as 0.33.]
在屏幕上设定打印精度为 [0.01 v]
在屏幕上打印 ([1] [math_division v] [3])▶

A screenshot of the V5 Brain screen showing the text "0.33" in the upper left corner.

设置屏幕上的笔宽#

设置屏幕上的笔宽 模块用于设置绘制线条和形状时使用的笔宽。

设置笔宽块#
设定屏幕笔宽为 [10]

参数

描述

宽度

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

例子

启动时,将笔的宽度设置为 10 像素,并绘制一个左上角位于 (50,50)、宽度为 130 像素、高度为 60 像素的矩形。#
当开始
[Draw a rectangle with a pen width of 10.]
设定屏幕笔宽为 [10]
在屏幕 [50] [50] [130] [60] 上画矩形

A screenshot of the V5 Brain screen showing a rectangle with thick borders printed in the upper left quadrant of the screen.

设置屏幕上的笔/字体颜色#

设置屏幕上的笔/字体颜色 模块用于设置机器人屏幕上绘制线条、形状和文本时使用的笔颜色。

设置笔字体颜色#
设定屏幕笔/字体颜色为 [红色 v]

参数

描述

颜色

设置画笔颜色:

  • 红色
  • 绿色
  • 蓝色
  • 黑色
  • 白色
  • 黄色
  • 橙色
  • 紫色
  • 青色
  • 透明

例子

启动时,将画笔颜色设置为橙色,并绘制一个左上角位于 (50, 50) 的矩形,宽度为 130 像素,高度为 60 像素。#
当开始
[Draw a rectangle with orange borders.]
设定屏幕笔/字体颜色为 [orange v]
在屏幕 [50] [50] [130] [60] 上画矩形

A screenshot of the V5 Brain screen showing a rectangle drawn in orange in the upper left quadrant of the screen.

设置屏幕填充颜色#

设置屏幕填充颜色 模块用于设置绘制形状时使用的填充颜色。

设置填充颜色堆叠块#
设定屏幕填充色为 [红色 v]

参数

描述

颜色

设置填充颜色:

  • 红色
  • 绿色
  • 蓝色
  • 黑色
  • 白色
  • 黄色
  • 橙色
  • 紫色
  • 青色
  • 透明

示例

启动时,将填充颜色设置为紫色,并绘制一个矩形。矩形位于 (50, 130) 处,宽度为 100 像素,高度为 60 像素。#
当开始
[Draw a purple rectangle.]
设定屏幕填充色为 [purple v]
在屏幕 [50] [130] [100] [60] 上画矩形

A screenshot of the V5 Brain screen showing a rectangle filled with purple in the lower left quadrant of the screen.

#

在屏幕上绘制像素#

在屏幕上绘制像素 块在指定的 (x, y) 屏幕坐标处以当前 画笔颜色 绘制像素。

绘制像素堆栈块#
在屏幕 [0] [0] 上画点

参数

描述

x

绘制像素的 x 坐标,范围从 0 到 479。

绘制像素的 y 坐标,范围从 0 到 239。

例子

启动时,在屏幕中心坐标 (120, 120) 处绘制一个像素。#
当开始
[Draw the pixels marking the corners of a square.]
在屏幕 [250] [100] 上画点
在屏幕 [275] [100] 上画点
在屏幕 [250] [125] 上画点
在屏幕 [275] [125] 上画点

A screenshot of the V5 Brain screen showing an assortment of pixels showing the corners of a square near the center of the screen.

在屏幕上画线#

在屏幕上绘制线条 模块使用当前的 笔宽笔颜色 从第一个指定的屏幕坐标 (x1, y1) 到第二个指定的屏幕坐标 (x2, y2) 绘制一条线。

绘制线条堆叠块#
在屏幕 [0] [0] [10] [10] 上画线段

参数

描述

x1

行首的 x 坐标(像素),范围从 0 到 479。

y1

线段起始点的 y 坐标(像素),取值范围为 0 到 239。

x2

行尾的 x 坐标(像素),范围从 0 到 479。

y2

线段末端的 y 坐标(像素),取值范围为 0 到 239。

例子

启动时,从屏幕左上角 (0,0) 到右下角 (240,240) 画一条对角线。#
当开始
[Draw a line from the top left to bottom right of the screen.]
在屏幕 [0] [0] [479] [239] 上画线段

A screenshot of the V5 Brain screen shows a thin diagonal line across the center, from the upper left corner to the lower right corner.

在屏幕上绘制矩形#

在屏幕上绘制矩形 模块使用当前的 画笔宽度画笔颜色填充颜色 绘制矩形。

绘制矩形块#
在屏幕 [0] [0] [10] [10] 上画矩形

参数

描述

x

矩形左上角的 x 坐标(像素),取值范围为 0 到 479。

矩形左上角的 y 坐标(像素),取值范围为 0 到 239。

宽度

矩形的宽度(以像素为单位)。

高度

矩形的高度(以像素为单位)。

例子

启动时,在屏幕上绘制一个矩形,左上角位于 (50,50),宽度为 130 像素,高度为 60 像素。#
当开始
[Draw a rectangle on the screen.]
在屏幕 [50] [50] [130] [60] 上画矩形

A screenshot of the V5 Brain's screen shows a rectangle with a thin white border printed in the upper left quadrant.

在屏幕上画一个圆#

在屏幕上绘制圆形 模块使用当前的 画笔宽度画笔颜色填充颜色 绘制圆形。

画圆 堆叠方块#
在屏幕 [0] [0] [10] 上画圆形

参数

描述

x

圆心的 x 坐标(像素值),取值范围为 0 到 479。

圆心的 y 坐标(像素值),取值范围为 0 到 239。

半径

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

例子

启动时,在屏幕上绘制一个圆,圆心位于 (120,120),半径为 40 像素。#
当开始
[Draw a circle on the screen.]
在屏幕 [120] [120] [40] 上画圆形

A screenshot of the V5 Brain screen shows a circle with a thin white border drawn in the center.

触碰#

屏幕被按下?#

屏幕是否被按下? 模块返回一个布尔值,指示大脑的触摸屏当前是否被按下。

  • 正确——屏幕正在被按下。

  • 错误——屏幕未被按下。

画圆 堆叠方块#
<屏幕按下了?>

参数

描述

此代码块没有参数。

启动时,在屏幕上绘制一个圆,圆心位于 (120,120),半径为 40 像素。#
当开始
[Change the screen's color after it's pressed.]
等到 <屏幕按下了?>
设定屏幕填充色为 [绿色 v]
在屏幕 [0] [0] [479] [239] 上画矩形
When the screen is pressed, the first message is shown. The code then waits until the screen is released, and only continues after the screen is pressed again to show the second message.#
当开始
[Display different messages after the screen is pressed.]
等到 <屏幕按下了?>
在屏幕上打印 [First message!]▶
在屏幕上设定光标至下一行
[Lift finger to press the screen again.]
等到 <非 <屏幕按下了?>>
等到 <屏幕按下了?>
在屏幕上打印 [Second message!]▶

屏幕位置#

屏幕位置 模块返回大脑触摸屏上次被按下位置的 x 或 y 坐标。

画圆 堆叠方块#
(屏幕 [X v] 坐标)

参数

描述

要返回哪个轴的位置:

  • x – 0 到 479
  • y – 0 到 239

启动时,在屏幕上绘制一个圆,圆心位于 (120,120),半径为 40 像素。#
当开始
[Display a circle where the screen is pressed.]
等到 <屏幕按下了?>
设定屏幕填充色为 [white v]
在屏幕 (屏幕 [X v] 坐标) (屏幕 [y v] 坐标) [20] 上画圆形

屏幕#

when screen 模块会在按下或释放 Brain 屏幕时运行所连接的模块堆栈。

画圆 堆叠方块#
当Brain屏幕 [pressed v] :: hat events

参数

描述

状态

何时运行所连接的积木栈:

  • 按下
  • 释放

启动时,在屏幕上绘制一个圆,圆心位于 (120,120),半径为 40 像素。#
当Brain屏幕 [pressed v] :: hat events
[Color the screen with polka dots by pressing it repeatedly.]
设定屏幕填充色为 [红色 v]
在屏幕 (屏幕 [X v] 坐标) (屏幕 [y v] 坐标) [20] 上画圆形