屏幕#

介绍#

The Screen blocks control how the VEX AIM Coding Robot shows text, numbers, and graphics on its screen, and how it responds to screen presses.

以下是所有模块的列表:

光标打印 — 使用行列光标系统管理文本显示。

XY 打印 — 按像素坐标打印文本。

设置 — 自定义文本格式和屏幕显示。

绘图——创建图形和视觉元素。

触摸 — 检测屏幕交互。

  • screen pressed — Reports whether the screen is currently being pressed.

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

  • when screen event — Runs attached blocks when the screen is pressed or released.

光标打印#

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

The set cursor to row column on screen stack block moves the cursor to a specific row and column on the robot’s 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.

设置游标堆栈块#
set cursor to row [1] column [1] on screen

参数

描述

The row to move the cursor to.

柱子

The column to move the cursor to.

示例

启动时,将光标移动到屏幕上的第 3 行、第 2 列,并打印“第 3 行、第 2 列”。#
when started
[Display text starting at Row 3 Column 2.]
set cursor to row (3) column (2) on screen
print [Row 3, Column 2] on screen ▶

机器人屏幕的截图,屏幕中心上方用白色字体打印了第 3 行第 2 列,从第 3 行第 2 列开始。

when started
[Display cargo amounts in an organized list.]
set font to [proportional v] [large v] on screen
print [Sports Balls] on screen ◀ and set cursor to next row
print [Orange Barrels] on screen ◀ and set cursor to next row
print [Blue Barrels] on screen ▶
set cursor to row [1] column [11] on screen
print [2] on screen ▶
set cursor to row [2] column [11] on screen
print [3] on screen ▶
set cursor to row [3] column [11] on screen
print [3] on screen ▶

机器人屏幕的截图显示三行白色文字,分别列出“运动球 2”、“橙色桶 3”和“蓝色桶 3”。数字位于每个标签的右侧,列表从屏幕顶部开始。

when started
[Display the ID of the detected AprilTag.]
set font to [proportional v] [extra large v] on screen
forever
clear screen
print [AprilTag] on screen ▶
get [all AprilTags v] data from AI Vision
if <AI Vision object exists?> then
set cursor to row [3] column [4] on screen
print (AI Vision object [tagID v]) on screen ▶
结束
wait [0.1] seconds

机器人屏幕的截图,屏幕中央附近印有白色文字,第一行是 AprilTag,第二行是 4。

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

The set cursor to next row on screen stack block moves the cursor to column 1 on the next row on the robot’s screen.

将光标设置到下一行堆栈块#
set cursor to next row on screen

参数

描述

该块没有参数。

例子

启动时,在屏幕上打印“第 1 行”,将光标移动到下一行,然后打印“第 2 行”。#
when started
[Display two lines of text.]
print [Line 1] on screen ▶
set cursor to next row on screen
print [Line 2] on screen ▶

机器人屏幕的截图,文字为白色。屏幕顶部左对齐显示“第 1 行”,下方紧邻“第 2 行”。

屏幕上的清除行#

The clear row on screen stack block clears a single row of text on the robot’s screen.

清除行堆栈块#
clear row [1] on screen

参数

描述

要清除的行号。

例子

启动后,打印两行文本。第一行保留,第二行在 3 秒后消失。#
when started
[Display text on two rows.]
print [This text stays] on screen ▶
set cursor to next row on screen
print [This text disappears] on screen ▶
wait [3] seconds
clear row [2] on screen

屏幕光标列#

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

屏幕光标列报告块#
(screen cursor column)

参数

描述

该块没有参数。

例子

启动时,将光标移动到屏幕上的第 3 行、第 2 列,并打印当前光标列号。#
when started
[Display the cursor's current column.]
set cursor to row [3] column [2] on screen
print (screen cursor column) on screen ▶

机器人屏幕的截图,左上象限中心附近,第 3 行第 2 列,印有一个白色的数字 2。

屏幕光标行#

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

屏幕光标行报告块#
(screen cursor row)

参数

描述

该块没有参数。

例子

启动后,将光标移动到屏幕上的第 6 行、第 2 列,并打印当前光标行号。#
when started
[Display the cursor's current row.]
set cursor to row [3] column [2] on screen
print (screen cursor row) on screen ▶

机器人屏幕的截图,左上象限中心附近,第 3 行第 2 列,印有一个白色的数字 3。

XY打印#

设置屏幕原点#

The set screen origin stack block changes the origin (0, 0) used for drawing or printing on the robot’s screen. By default, the origin is the top-left corner of the screen. This block can reset the origin to an alternate (x, y) screen coordinate location.

设置屏幕原点堆栈块#
set screen origin x:[0] y:[0]

参数

描述

x

The x-coordinate in pixels to set as the new origin.

y

The y-coordinate in pixels to set as the new origin.

例子

启动时,将屏幕原点设置为 (120, 120),并在新原点处绘制一个矩形,其左上角位于 (0,0)、宽度为 80 像素,高度为 40 像素。#
when started
[Set the origin to the center of the screen.]
set screen origin x:[120] y:[120]
[Draw a rectangle at the new origin.]
draw rectangle [0] [0] [80] [40] on screen

机器人屏幕的截图,左下角绘制了一个白色矩形。矩形的左上角是屏幕中心。

设置#

清除屏幕#

The clear screen stack block clears all drawings and text from the robot’s screen and resets the cursor position to row 1, column 1.

clear screen stack block#
clear screen

参数

描述

该块没有参数。

例子

启动后,以 (120,120) 为圆心,半径为 40 像素绘制一个圆。2 秒后,屏幕清空。#
when started
[Draw a circle, and clear it after 2 seconds.]
draw circle [120] [120] [40] on screen
wait [2] seconds
clear screen

填满屏幕#

The fill screen stack block clears all drawings and text from the robot’s screen, then changes the background to a specified color.

fill screen stack block#
fill screen with [red v]

参数

描述

颜色

The background color to use:

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

例子

when started
[Say "Hello" then turn screen yellow.]
print [Hello] on screen ▶
wait [2] seconds
fill screen with [yellow v]

设置屏幕上的字体#

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

设置字体堆栈块#
set font to [monospaced v] [super small v] on screen

参数

描述

类型

The font type: monospaced or proportional

尺寸

The font size (shown below):

  • super small
  • extra small
  • small
  • medium
  • large
  • extra large
  • super large

机器人屏幕截图,显示以 Mono 12 字体打印的数字和字母示例。字母表占据一行文本。底部文字横向 26 个字符,共 15 行。
等宽超小号

与上一张图片相同,但字体为 Mono 15。字母 AT 占据一行文字。底部文字为 20 个字符宽,12 行。(/_static/img/fonts/mono15.png)
等宽特小号

与上一张图片相同,但字体为 Mono 20。字母 AP 占据一行文字。底部文字为 16 个字符宽,共 9 行。(/_static/img/fonts/mono20.png)
等宽小号

与上一张图片相同,但字体为 Mono 24。字母 AM 占据一行文字。底部文字横向 13 个字符,共 8 行。(/_static/img/fonts/mono24.png)
等宽中等字体

与上一张图片相同,使用 Mono 30 字体。字母 AK 占据一行文字。底部文字横向 11 个字符,共 6 行。
等宽大号

与上一张图片相同,使用 Mono 40 字体。字母 AH 占据一行文字。底部文字横向 8 个字符,共 5 行。
等宽特大号

与上一张图片相同,使用 Mono 60 字体。数字 1-6 占据一行文字。底部文字占据三行。
等宽超大号

与上一张图片相同,但使用 Prop 20 字体。字母 As 占据一行文本。底部文字为 20 个字符宽,9 行高。
比例小

与上一张图片相同,但使用 Prop 30 字体。字母 AM 占据一行文字。底部文字为 15 个字符,共 6 行。
比例大

与上一张图片相同,但使用 Prop 40 字体。字母 AJ 占据一行文字。底部文字为 11 个字符,共 5 行。
比例超大

机器人屏幕截图,显示以 Prop 60 字体打印的数字样本。数字 1-7 占据一行文本。底部显示 7 行 3 列。
比例超大

例子

启动时,将字体设置为“等宽超大”并在屏幕上打印“VEX”。#
when started
[Display text using a larger font]
set font to [monospaced v] [extra large v] on screen
print [VEX] on screen ▶

机器人屏幕的截图显示,左上角用白色 Mono 40 字体打印着 VEX 字样。

设置屏幕打印精度#

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

设置打印精度堆栈块#
set print precision to [0.1 v] on screen

参数

描述

精确

The print precision to use:

  • 1
  • 0.1
  • 0.01
  • 0.001
  • All Digits

例子

启动时,将打印精度设置为小数点后两位,并在屏幕上将 1/3 打印为 0.33。#
when started
[Print 1/3 as 0.33.]
set print precision to [0.01 v] on screen
print ([1] [math_division v] [3]) on screen ▶

机器人屏幕的截图左上角显示白色数字 0.33。

设置屏幕上的笔宽#

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

set pen width stack block#
set pen width to [10] on screen

参数

描述

宽度

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

例子

启动时,将笔宽设置为10像素,并绘制一个矩形,其左上角位于(50,50),宽度为130像素,高度为60像素。#
when started
[Draw a rectangle with a pen width of 10.]
set pen width to [10] on screen
draw rectangle [50] [50] [130] [60] on screen

机器人屏幕的截图,上半部分画着一个粗白矩形。

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

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#
set pen / font color to [red v] on screen

参数

描述

颜色

The pen and font color to use:

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

例子

启动时,将画笔颜色设置为红色,并绘制一个矩形,左上角位于(50,50),宽度为130像素,高度为60像素。#
when started
[Draw a rectangle with a red pen.]
set pen / font color to [red v] on screen
draw rectangle [50] [50] [130] [60] on screen

机器人屏幕的截图,上半部分画着一个细边框的红色矩形。

设置屏幕填充颜色#

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

设置填充颜色堆栈块#
set fill color to [red v] on screen

参数

描述

颜色

The fill color to use:

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

示例

启动后,将填充颜色设置为橙色,并绘制两个矩形。第一个矩形位于 (50, 50),第二个矩形位于 (50, 130),宽度均为 100 像素,高度均为 60 像素。#
when started
[Draw two orange rectangles.]
set fill color to [orange v] on screen
draw rectangle [50] [50] [100] [60] on screen
draw rectangle [50] [130] [100] [60] on screen

机器人屏幕的截图,屏幕左侧中央有两个平行的橙色矩形,带有细细的白色轮廓。


启动时,将背景填充颜色设置为紫色并在屏幕上打印“高亮”。#
when started
[Display text with a purple background.]
set fill color to [purple v] on screen
print [Highlight] on screen ▶

机器人屏幕的截图显示“高亮显示”,白色文字周围有紫色高亮圈,从左上角开始。

#

在屏幕上显示图像文件#

The show image file on screen stack block draws a custom user-uploaded image on the robot’s screen.

显示用户图像堆栈块#
show image file [1 v]

参数

描述

图像槽号

要使用的自定义图像,编号 1 到 10。图像编号与 AIM 控制面板中显示的数字一致。

例子

when started
[Draw uploaded Image 1.]
show image file [1 v]

在屏幕上绘制像素#

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

By default, the origin is located at the top-left corner of the screen at (0, 0). On the x-axis, 0 is on the left side of the screen, and 240 is on the right side. On the y-axis, 0 is at the top of the screen, and 240 is at the bottom. You can use the set screen origin block to move the origin to a different location. When the origin is changed, the x- and y-coordinate ranges will also change.

For example, if the origin is set to (120, 120), the x and y range will be from -120 to 120 for the x and y coordinates.

绘制像素堆栈块#
draw pixel [0] [0] on screen

参数

描述

x

The x-coordinate to draw the pixel, from 0 to 240 with the default origin.

y

The y-coordinate to draw the pixel, from 0 to 240 with the default origin.

例子

启动时,在屏幕中心坐标 (120, 120) 处绘制一个像素。#
when started
[Draw a pixel at the center of the screen.]
draw pixel [120] [120] on screen

机器人屏幕的截图,中心有一个白色像素。

在屏幕上画线#

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.

By default, the origin is located at the top-left corner of the screen at (0, 0). On the x-axis, 0 is on the left side of the screen, and 240 is on the right side. On the y-axis, 0 is at the top of the screen, and 240 is at the bottom. You can use the set screen origin block to move the origin to a different location. When the origin is changed, the x- and y-coordinate ranges will also change.

For example, if the origin is set to (120, 120), the x and y range will be from -120 to 120 for the x and y coordinates.

画线堆叠块#
draw line [0] [0] [10] [10] on screen

参数

描述

x1

The x-coordinate in pixels of the start of the line, from 0 to 240 with the default origin.

y1

The y-coordinate in pixels of the start of the line, from 0 to 240 with the default origin.

x2

The x-coordinate in pixels of the end of the line, from 0 to 240 with the default origin.

y2

The y-coordinate in pixels of the end of the line, from 0 to 240 with the default origin.

例子

启动时,从屏幕左上角(0,0)到右下角(240,240)绘制一条对角线。#
when started
[Draw a line from the top left to bottom right of the screen.]
draw line [0] [0] [240] [240] on screen

机器人屏幕的截图,从左上角到右下角画了一条细细的白色对角线。

在屏幕上绘制矩形#

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

By default, the origin is located at the top-left corner of the screen at (0, 0). On the x-axis, 0 is on the left side of the screen, and 240 is on the right side. On the y-axis, 0 is at the top of the screen, and 240 is at the bottom. You can use the set screen origin block to move the origin to a different location. When the origin is changed, the x- and y-coordinate ranges will also change.

For example, if the origin is set to (120, 120), the x and y range will be from -120 to 120 for the x and y coordinates.

draw rectangle stack block#
draw rectangle [0] [0] [10] [10] on screen

参数

描述

x

The x-coordinate in pixels of the top-left corner of the rectangle, from 0 to 240 with the default origin.

y

The y-coordinate in pixels of the top-left corner of the rectangle, from 0 to 240 with the default origin.

宽度

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

高度

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

例子

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

机器人屏幕的截图,上半部分画了一个白色矩形。

在屏幕上画一个圆#

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

By default, the origin is located at the top-left corner of the screen at (0, 0). On the x-axis, 0 is on the left side of the screen, and 240 is on the right side. On the y-axis, 0 is at the top of the screen, and 240 is at the bottom. You can use the set screen origin block to move the origin to a different location. When the origin is changed, the x- and y-coordinate ranges will also change.

For example, if the origin is set to (120, 120), the x and y range will be from -120 to 120 for the x and y coordinates.

画圆堆叠块#
draw circle [0] [0] [10] on screen

参数

描述

x

The x-coordinate in pixels of the center of the circle, from 0 to 240 with the default origin.

y

The y-coordinate in pixels of the center of the circle, from 0 to 240 with the default origin.

半径

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

例子

启动时,在屏幕上绘制一个圆心为(120,120)、半径为40像素的圆圈。#
when started
[Draw a circle on the screen.]
draw circle [120] [120] [40] on screen

机器人屏幕的截图,中心画有一个白色圆圈。

触碰#

screen pressed#

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

  • True — The screen is being pressed.

  • False — The screen is not being pressed.

screen pressed Boolean block#
<screen pressed?>

参数

描述

该块没有参数。

例子

启动后,持续检测屏幕是否被按下。如果被按下,所有 LED 灯亮起白色;否则,所有 LED 灯保持熄灭。#
when started
[Turn LEDs white only when the screen is pressed.]
forever
if <screen pressed?> then
set [lightall v] LED color to [white v]
else
set [lightall v] LED color to [off v]
结束
结束

屏幕位置#

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

屏幕位置报告块#
(screen [x v] position)

参数

描述

协调

The coordinate of the last screen press to report: x reports the horizontal position, and y reports the vertical position.

例子

启动后,持续检测屏幕是否按下。如果按下,则清除屏幕并打印触摸位置的 x 和 y 坐标。#
when started
[Display the x and y coordinate of where the screen is pressed.]
forever
if <screen pressed?> then
clear screen
print (screen [x v] position) on screen ▶
set cursor to next row on screen
print (screen [y v] position) on screen ▶
结束
结束

当屏幕事件#

The when screen event hat block runs the attached stack of blocks when the robot’s screen is pressed or released.

when screen event hat block#
when screen [pressed v]

参数

描述

行动

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

例子

按下屏幕时,所有 LED 均变为绿色。#
when screen [pressed v]
[Set the LEDs to green when the screen is pressed.]
set [lightall v] LED color to [green v]