屏幕#

介绍#

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

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

For drawing, the Brain’s resolution is 480 x 240 pixels.

V5 大脑屏幕,红色网格线显示了总共 12 行 48 列的布局。像素尺寸为 479 宽 x 239 高。左上角起始于 (0,0) 像素,位于第 1 行第 1 列;右下角结束于 (479, 239) 像素,位于第 12 行第/_static/img/screen/brain-resolution.png列。

以下是可用模块列表:

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

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

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

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

  • screen pressed – Reports whether the screen is currently being touched.

  • screen position – Reports the selected x or y coordinate of the last screen press.

  • 当屏幕 – 当屏幕被按下或释放时运行附加的模块。

光标打印#

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

The set cursor to row column on screen stack block moves the cursor to a specific row and column on the Brain screen. The next print on screen block will start printing at that location. How many rows and columns can comfortably fit depends on the selected font. With the default monospaced medium font, up to 8 rows and 13 columns can be displayed clearly. Text placed beyond this range may be cut off or become difficult to read.

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, the set cursor to row column on screen stack block positions the cursor based on row and column size, not font style. The font size can be adjusted using the set font on screen stack block.

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

参数

描述

The row to move the cursor to.

柱子

The column to move the cursor to.

例子

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

V5 Brain 的屏幕截图,显示屏幕上方靠近中心位置打印的第 3 行第 12 列。

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

The set cursor to next row on screen stack block moves the cursor to column 1 on the next row on the Brain screen.

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

参数

描述

此代码块没有参数。

例子

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

V5 Brain 屏幕的截图,显示左上角有两行白色文字。上面一行是“第 1 行”,紧挨着它的第二行是“第 2 行”。

屏幕上的清除行#

The clear row on screen stack block clears a single row of text on the Brain screen.

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

参数

描述

要清除的行号。

例子

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

屏幕光标列#

The screen cursor column reporter block reports the column number where text will be printed as an integer.

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

参数

描述

此代码块没有参数。

例子

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

V5 Brain 屏幕的屏幕截图,显示屏幕左上角第 3 行第 15 列位置的白色文字“15”。

屏幕光标行#

The screen cursor row reporter block reports the row number where text will be printed as an integer.

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

参数

描述

此代码块没有参数。

例子

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

V5 Brain 屏幕的屏幕截图,显示屏幕左上角第 3 行第 2 列位置的白色文字“3”。

设置#

清晰屏幕#

The clear screen stack block clears all drawings and text from the Brain screen.

clear screen stack block#
清屏

参数

描述

此代码块没有参数。

例子

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

设置屏幕上的字体#

The set font on screen stack block sets the font and size used for displaying text on the Brain screen. This font will apply to all subsequently printed text.

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

参数

描述

风格

The font style: monospaced or proportional

尺寸

The font size (examples below):

  • extra small
  • small
  • medium
  • large
  • extra large
  • super large
Note: Extra small and small sizes are not available for proportional fonts.

V5 Brain 屏幕截图,左上角以白色 MONO 12 字体打印数字和字母。其中一行显示 AZ,约占屏幕宽度的四分之一。左下角显示 80 列和 20 行。
等宽超小号

与上一张图片相同,但字体为 Mono 15。图中一行显示“AZ”,几乎占据了屏幕一半的宽度。左下角显示“68 列
行/_static/img/fonts/mono15.png。

与上一张图片相同,但字体为 Mono 20。图中一行显示“AZ”,占据了屏幕宽度的近三分之二。左下角显示“48 列
行/_static/img/fonts/mono20.png。

与上一张图片相同,但字体为 Mono 30。图中一行显示 AZ,几乎占据了整个屏幕宽度。左下角显示“32 列
行/_static/img/fonts/mono30.png。

与上一张图片相同,但字体为 Mono 40。图中一行显示 AX,横跨屏幕宽度。左下角显示“24 列
行/_static/img/fonts/mono40.png。

与上一张图片相同,但字体为 Mono 60。图片中一行显示 AP 字样,横跨屏幕宽度。底部显示“16 列
行/_static/img/fonts/mono60.png。

与上一张图片相同,但字体为 Prop 20。图中一行显示“AZ”,占据了屏幕宽度的近三分之二。左下角显示“48 列 12 行”。(/_static/img/fonts/prop20.png)
比例中等

与上一张图片相同,但字体为 Prop 30。图中一行显示“AZ”,几乎占据了整个屏幕宽度。左下角显示“32 列 8 行”。
比例大

与上一张图片相同,但字体为 Prop 40。图中一行显示“AU”,横跨屏幕宽度。左下角显示“24 列 6 行”。
比例超大

与上一张图片相同,但字体为 Prop 60。图片中一行显示“AN”,横跨屏幕宽度。底部显示“15 列 4 行”。
比例超大

例子

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

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

设置屏幕打印精度#

The set print precision on screen stack block sets how many decimal places to show when printing numbers on the Brain screen. This print precision will apply to all subsequently printed numbers.

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

参数

描述

精确

The print precision to use:

  • 1
  • 0.1
  • 0.01
  • 0.001
  • All Digits

例子

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

V5 Brain 屏幕的截图,左上角显示文字“0.33”。

设置屏幕上的笔宽#

The set pen width on screen stack block sets the thickness of drawn lines and shape outlines.

set pen width stack block#
设定屏幕笔宽为 [10]

参数

描述

宽度

The pen width, in pixels, from 0 to 32.

例子

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

V5 Brain 屏幕的屏幕截图,显示屏幕左上角打印着一个带有粗边框的矩形。

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

The set pen / font color on screen stack block sets the color of text, pixels, lines, and shape outlines.

set pen / font color stack block#
设定屏幕笔/字体颜色为 [红色 v]

参数

描述

颜色

The pen and font color to use:

  • red
  • green
  • blue
  • black
  • white
  • yellow
  • orange
  • purple
  • cyan
  • transparent

例子

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

V5 Brain 屏幕的截图,显示屏幕左上角有一个橙色矩形。

设置屏幕填充颜色#

The set fill color on screen stack block sets the fill color used when shapes are drawn.

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

参数

描述

颜色

The fill color to use:

  • red
  • green
  • blue
  • black
  • white
  • yellow
  • orange
  • purple
  • cyan
  • transparent

示例

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

V5 Brain 屏幕的截图,显示屏幕左下角有一个填充紫色的矩形。

#

在屏幕上绘制像素#

The draw pixel on screen stack block draws one pixel at the selected x and y coordinate using the current pen color.

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

参数

描述

x

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

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

例子

When started, draws four pixels that mark the corners of a small square.#
当开始
[Draw the pixels marking the corners of a square.]
在屏幕 [250] [100] 上画点
在屏幕 [275] [100] 上画点
在屏幕 [250] [125] 上画点
在屏幕 [275] [125] 上画点

V5 Brain 屏幕的截图,显示屏幕中心附近一个正方形的四个角由各种像素组成。

在屏幕上画线#

The draw line on screen stack block draws a line from the first screen coordinate (x1, y1) to the second screen coordinate (x2, y2) using the current pen width and pen color.

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

参数

描述

x1

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

y1

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

x2

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

y2

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

例子

When started, draws a diagonal line from the top-left corner (0, 0) to the bottom-right corner (479, 239) of the screen.#
当开始
[Draw a line from the top left to bottom right of the screen.]
在屏幕 [0] [0] [479] [239] 上画线段

V5 Brain 屏幕的截图显示,屏幕中心有一条细斜线,从左上角延伸到右下角。

在屏幕上绘制矩形#

The draw rectangle on screen stack block draws a rectangle using the current pen width, pen color, and fill color.

draw rectangle stack block#
在屏幕 [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] 上画矩形

V5 大脑屏幕的截图显示,左上象限打印着一个带有细白边框的矩形。

在屏幕上画一个圆#

The draw circle on screen stack block draws a circle using the current pen width, pen color, and fill color.

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

参数

描述

x

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

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

半径

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

例子

When started, draws a circle on the screen with the center at (120, 120) and a radius of 40 pixels.#
当开始
[Draw a circle on the screen.]
在屏幕 [120] [120] [40] 上画圆形

V5 Brain 屏幕的截图显示,中心画有一个带有细白边框的圆圈。

触碰#

screen pressed#

The screen pressed Boolean block reports whether the Brain’s touchscreen is currently being pressed.

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

screen pressed Boolean block#
<屏幕按下了?>

参数

描述

此代码块没有参数。

When started, changes the screen color after the screen is pressed.#
当开始
[Change the screen's color after it's pressed.]
等到 <屏幕按下了?>
设定屏幕填充色为 [绿色 v]
在屏幕 [0] [0] [479] [239] 上画矩形
按下屏幕后,会显示第一条信息。然后,程序会等待屏幕松开,只有在再次按下屏幕后才会继续显示第二条信息。#
当开始
[Display different messages after the screen is pressed.]
等到 <屏幕按下了?>
在屏幕上打印 [First message!]▶
在屏幕上设定光标至下一行
[Lift finger to press the screen again.]
等到 <非 <屏幕按下了?>>
等到 <屏幕按下了?>
在屏幕上打印 [Second message!]▶

屏幕位置#

The screen position reporter block reports the selected coordinate of the last screen press. The x-coordinate is from 0 (left) to 479 (right). The y-coordinate is from 0 (top) to 239 (bottom).

screen position reporter block#
(屏幕 [X v] 坐标)

参数

描述

The coordinate of the last screen press to report: x – The horizontal position or y – The vertical position

When the Brain screen is pressed, draws a circle at the press location.#
当开始
[Display a circle where the screen is pressed.]
等到 <屏幕按下了?>
设定屏幕填充色为 [white v]
在屏幕 (屏幕 [X v] 坐标) (屏幕 [y v] 坐标) [20] 上画圆形

屏幕#

The when screen hat block runs the attached stack of blocks when the Brain screen is pressed or released.

when screen hat block#
当Brain屏幕 [pressed v] :: hat events

参数

描述

状态

When to run the attached stack of blocks: pressed runs when the screen is pressed, and released runs when the screen is released.

When the Brain screen is pressed, draws a circle at the press location.#
当Brain屏幕 [pressed v] :: hat events
[Color the screen with polka dots by pressing it repeatedly.]
设定屏幕填充色为 [红色 v]
在屏幕 (屏幕 [X v] 坐标) (屏幕 [y v] 坐标) [20] 上画圆形