屏幕#

介绍#

The VEX AIM Coding Robot’s screen provides methods for displaying text, managing the cursor, drawing shapes, and handling touch interactions.

Below is a list of all available methods:

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

  • print – 在当前光标位置打印文本。

  • set_cursor – 将光标设置到特定的行和列。

  • next_row – 将光标移动到下一行的第 1 列。

  • clear_row – 清除一行文本。

  • get_row – 返回当前光标行。

  • get_column – 返回当前光标列。

XY 打印 – 在特定的屏幕坐标处显示文本。

  • print_at – 在特定的 x 和 y 位置打印文本。

  • set_origin – 设置打印和绘图的新原点。

改变器——清除屏幕或更新视觉设置。

绘图——在屏幕上添加图形和图像。

触摸——检测并响应屏幕按压。

  • x_position – 返回按下屏幕的 x 坐标。

  • y_position – 返回按下屏幕的 y 坐标。

  • pressing – 返回屏幕当前是否被按下。

回调——当按下或释放屏幕时运行函数。

  • pressed – 注册一个在按下屏幕时调用的函数。

  • released – 注册在屏幕释放时调用的函数。

光标打印#

print#

print 在机器人屏幕上的当前 光标位置字体 显示文本。

用法:
robot.screen.print(text)

参数

描述

文本

要在屏幕上显示的文本、数字或变量值。

# Display a message at the starting cursor position
robot.screen.print("Hello, Robot!")

显示 robot.screen.print 方法,并显示单词“Hello Robot!”

set_cursor#

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

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, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using set_font.

用法:
robot.screen.set_cursor(row, column)

参数

描述

游标所在行。

光标所在的列。

# Display text starting at Row 3 Column 2
robot.screen.set_cursor(3, 2)
robot.screen.print("Row 3, Column 2")

显示 robot.screen.print_at 方法,将第 3 行、第 2 列打印在第 3 行第 2 列

next_row#

next_row 将光标移动到机器人屏幕下一行的第 1 列。

用法:
robot.screen.next_row()

参数

描述

该方法没有参数。

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

显示 robot.screen.next_row 方法,其中第 1 行和第 2 行分别打印在机器人屏幕上的第 1 行和第 2 行。

clear_row#

clear_row 清除机器人屏幕上的一行文本。

用法:
robot.screen.clear_row(row, color)

范围

描述

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

颜色

可选。应用于已清除行的颜色。选项包括:

  • 黑色
  • 蓝色</li><li>青色</li><li>绿色</li><li>橙色
  • 紫色
  • 红色</li><li>透明
  • 白色</li><li>黄色
您还可以指定 自定义颜色

# Display text on two rows
robot.screen.print("This text stays")
robot.screen.next_row()
robot.screen.print("This text disappears")

# Wait 3 seconds before clearing only the second row
wait(3, SECONDS)
robot.screen.clear_row()

# Turn the 5th row green
robot.screen.clear_row(5, GREEN)

在屏幕第 5 行显示 robot.screen.clear_row 方法,并带有绿色条纹。

get_row#

get_row returns the current row where text will be printed as an integer.

用法:
robot.screen.get_row()

参数

描述

该方法没有参数。

# Set cursor to (3,2) and print row number
robot.screen.set_cursor(3, 2)
robot.screen.print(robot.screen.get_row())

当您将 curosr 设置为 3,2 时,通过显示行号 3 来显示 robot.screen.print_at 方法

get_column#

column 返回当前列,其中文本将以整数形式打印。

用法:
robot.screen.get_column()

参数

描述

该方法没有参数。

# Set cursor to (3,2) and print column number
robot.screen.set_cursor(3, 2)
robot.screen.print(robot.screen.get_column())

当您将 curosr 设置为 3,2 时,通过显示列号 2 来显示 robot.screen.print_at 方法

XY打印#

set_origin#

set_origin sets the origin (0, 0) used for drawing or printing on the robot’s screen. By default, drawing or printing methods consider the top left corner of the screen as the origin. This method can reset the origin to an alternate (x, y) screen coordinate location.

用法:
robot.screen.set_origin(x, y)

范围

描述

x

设置为原点的新 x 坐标,以 0 至 240 之间的整数形式给出。

y

设置作为原点的新 y 坐标,以 0 至 240 之间的整数形式给出。

# Set the origin to the center of the screen
robot.screen.set_origin(120, 120)

# Draw a rectangle at the new origin
robot.screen.draw_rectangle(0, 0, 80, 40)

机器人的屏幕显示一个白色矩形,左上角位于中心。

修改器#

clear_screen#

clear_screen 清除机器人屏幕上的所有图形和文本。默认情况下,它还会将光标位置重置为第 1 行第 1 列。

Usage:
robot.screen.clear_screen(color)

范围

描述

颜色

可选。设置屏幕颜色。选项包括:

  • 黑色
  • 蓝色</li><li>青色
  • 绿色
  • 橙色</li><li>紫色</li><li>红色
  • 16 透明
  • 白色</li><li>黄色
您还可以指定 自定义颜色

# Draw a circle, and clear it after 2 seconds
robot.screen.draw_circle(120, 120, 60)
wait(2, SECONDS)
robot.screen.clear_screen()

# Set the background color of the screen to red
robot.screen.clear_screen(RED)

机器人的屏幕完全是红色的。

set_font#

set_font 设置机器人屏幕上显示文本的字体。此字体将应用于所有使用 printprint_at 打印的文本。项目开始时的默认字体为 MONO24

用法:
robot.screen.set_font(fontname)

范围

描述

字体名称

将字体设置为下列之一:

  • MONO12
  • MONO15
  • MONO20
  • MONO24
  • MONO30
  • MONO40
  • MONO60
  • PROP20
  • PROP30
  • PROP40
  • PROP60
这些选项如下所示。

机器人用 MONO 12 字体在屏幕上打印数字和字母。它显示了 AZ。在屏幕底部,它有 26 个横排和 15 行。
MONO12

机器人屏幕上打印了 MONO 15 字体的数字和字母。显示为 AT。屏幕底部显示为 20 个字符,共 12 行。
MONO15

机器人屏幕上打印了 MONO 20 字体的数字和字母。显示为 AP。屏幕底部显示 16 个 9 行的字符。
MONO20

机器人屏幕上打印了 MONO 24 字体的数字和字母。显示为 AM。屏幕底部显示的数字为 13,横排 8 行。
MONO24

机器人屏幕上打印了 MONO 30 字体的数字和字母。它显示了 AK。在屏幕底部,它有 11 个字符,6 行。
MONO30

机器人屏幕上打印了 MONO 40 字体的数字和字母。它显示了 AK。屏幕底部有 8 个 5 行的字体。
MONO40

机器人屏幕上打印了 MONO 60 字体的数字和字母,显示 1-6。屏幕底部有 3 行。
MONO60

机器人屏幕上打印了PROP 20字体的数字和字母。它显示了AS。在屏幕底部,它有8个横排和9行。
PROP20

机器人屏幕上打印了PROP 30字体的数字和字母。显示为AM。屏幕底部显示的数字为15,共6行。
PROP30

机器人屏幕上打印了PROP 40字体的数字和字母。显示为AM。屏幕底部显示为15行6列。
PROP40

机器人屏幕上打印了带有 PROP 60 字体的数字和字母。它显示 1-7。屏幕底部有 7 个字,共 3 行。
PROP60

# Display text using a larger font
robot.screen.set_font(MONO40)
robot.screen.print("VEX")

机器人屏幕左上角显示Mono 40字体的“VEX”字样。

set_pen_width#

set_pen_width 设置用于绘制线条和形状的笔宽。

用法:
robot.screen.set_pen_width(width)

范围

描述

宽度

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

# Draw a rectangle with a pen width of 10
robot.screen.set_pen_width(10)
robot.screen.draw_rectangle(50, 50, 130, 60)

机器人的屏幕显示一个红色矩形,顶部居中画有一条细边框。

set_pen_color#

set_pen_color 设置用于绘制线条、形状和文本的画笔颜色。

用法:
robot.screen.set_pen_color(color)

范围

描述

颜色

可选。设置画笔颜色。选项包括:

  • 黑色
  • 蓝色</li><li>青色
  • 绿色
  • 橙色</li><li>紫色</li><li>红色
  • 16 透明
  • 白色</li><li>黄色
您还可以指定 自定义颜色

# Draw a rectangle with a red pen
robot.screen.set_pen_color(RED)
robot.screen.draw_rectangle(50, 50, 130, 60)

机器人的屏幕显示一个红色矩形,其顶部居中画有一条细边框。

set_fill_color#

set_fill_color 方法设置绘制形状时使用的填充颜色。

用法:
robot.screen.set_fill_color(color)

范围

描述

颜色

可选。设置填充颜色。选项包括:

  • 黑色
  • 蓝色</li><li>青色
  • 绿色
  • 橙色</li><li>紫色</li><li>红色
  • 16 透明
  • 白色</li><li>黄色
您还可以指定 自定义颜色

# Draw two orange rectangles
robot.screen.set_fill_color(ORANGE)
robot.screen.draw_rectangle(50, 50, 100, 60)
robot.screen.draw_rectangle(50, 130, 100, 60)

机器人的屏幕上显示两个平行的橙色矩形,带有白色的细边框,略微偏离中心左侧。

# Display text with a purple background
robot.screen.set_fill_color(PURPLE)
robot.screen.print("Highlight")

机器人的屏幕上显示白色文字“突出显示”,并从左上角开始打印,周围带有紫色突出显示。

#

draw_pixel#

draw_pixel 使用当前画笔颜色在指定的 (x, y) 屏幕坐标处绘制一个像素。它使用由 set_pen_color 设置的当前画笔颜色。

用法:
robot.screen.draw_pixel(x, y)

范围

描述

x

将绘制像素的 x 坐标,以 0 至 240 之间的整数表示。

y

将绘制像素的 y 坐标,以 0 至 240 之间的整数表示。

# Draw a pixel at the center of the screen
robot.screen.draw_pixel(120, 120)

机器人的屏幕中央显示一个白色像素。

draw_line#

draw_line draws a line from the first specified screen coordinate (x1, y1) to the second specified screen coordinate (x2, y2). It uses the current the pen width set by set_pen_width and pen color set by set_pen_color.

x 和 y 坐标使用默认原点 (0, 0),除非使用 set_origin 设置了不同的原点。

用法:
robot.screen.draw_line(x1,y1,x2,y2)

范围

描述

x1

线的起始 x 坐标,以 0 至 240 之间的整数表示。

y1

线的起始 y 坐标,以 0 至 240 之间的整数表示。

x2

线的结束 x 坐标,以 0 至 240 之间的整数表示。

y2

线的结束 y 坐标,以 0 至 240 之间的整数表示。

# Draw a line from the top left to bottom right of the screen
robot.screen.draw_line(0, 0, 240, 240)

机器人的屏幕显示一条从左上角到右下角穿过中心的细对角线。

draw_rectangle#

draw_rectangle 绘制一个矩形,其左上角位于指定的 (x, y) 坐标,其大小由给定的宽度和高度决定,所有值均以像素为单位。矩形的轮廓使用由 set_pen_width 设置的当前画笔宽度和由 set_pen_color 设置的画笔颜色绘制。矩形内部填充由 set_fill_color 设置的颜色。

x 和 y 坐标使用默认原点 (0, 0),除非使用 set_origin 设置了不同的原点。

用法:
robot.screen.draw_rectangle(x, y, width, height, color)

范围

描述

x

矩形左上角的 x 坐标,以 0 至 240 之间的整数表示。

y

矩形左上角的 y 坐标,以 0 至 240 之间的整数表示。

宽度

矩形的宽度,以 0 到 240 之间的整数表示。

高度

矩形的高度,以 0 到 240 之间的整数表示。

颜色

Optional. The fill color of the rectangle. Options include:

  • BLACK
  • BLUE
  • CYAN
  • GREEN
  • ORANGE
  • PURPLE
  • RED
  • TRANSPARENT
  • WHITE
  • YELLOW
You can also specify a custom color.

# Draw a red rectangle on the screen
robot.screen.draw_rectangle(50, 50, 130, 60, RED)

AIM机器人画矩形

draw_circle#

draw_circle 绘制一个圆,其圆心位于指定的 (x, y) 坐标,大小由给定的半径决定,所有尺寸均以像素为单位。圆的轮廓使用由 set_pen_width 设置的当前画笔宽度和由 set_pen_color 设置的画笔颜色绘制。圆的内部填充由 set_fill_color 设置的颜色。

x 和 y 坐标使用默认原点 (0, 0),除非使用 set_origin 设置了不同的原点。

用法:
robot.screen.draw_circle(x, y, radius, color)

范围

描述

x

圆心的 x 坐标,以 0 至 240 之间的整数表示。

y

圆心的 y 坐标,以 0 至 240 之间的整数表示。

半径

圆的半径,以 0 到 240 像素之间的整数表示。

颜色

可选。圆的填充颜色。选项包括:

  • 黑色
  • 蓝色</li><li>青色</li><li>绿色
  • 橙色</li><li>紫色</li><li>红色
  • 透明</li><li>白色
  • `黄色
您还可以指定 自定义颜色

# Draw a green circle on the screen
robot.screen.draw_circle(120, 120, 40, GREEN)

AIM机器人画圆

show_file#

show_file 在机器人的屏幕上显示自定义上传的图像,其位置使用基于图像参考点的 xycenter 参数设置。

用法:
robot.screen.show_file(file, x, y, center)

范围

描述

文件

要使用的自定义图像,从IMAGE1IMAGE10。图像编号与 AIM 控制面板中显示的编号一致。

x

图像的水平偏移量,以像素为单位的整数形式指定。正值表示向右移动;负值表示向左移动。

y

图像的垂直偏移量,以像素为单位的整数形式指定。正值表示向下移动;负值表示向上移动。

中心

可选。如果 center=True,则图像将以其中心坐标 (120, 120) 为中心进行放置。默认情况下 (center=False),将使用图像的左上角,并相对于当前 原点 进行定位。

# Display uploaded Image 1 in the top left corner
robot.screen.show_file(IMAGE1, 0, 0)

# Show the same image on both sides of the screen
# Image size is 120 x 120
robot.screen.show_file(IMAGE1, 65, 0, center=True)
robot.screen.show_file(IMAGE1, -65, 0, center=True)

set_clip_region#

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

用法:
robot.screen.set_clip_region(x, y, width, height)

范围

描述

x

剪辑区域左上角的 x 坐标,以 0 到 240 之间的整数或浮点数给出。

y

剪辑区域左上角的 y 坐标,以 0 到 240 之间的整数或浮点数表示。

宽度

剪辑区域的宽度(以像素为单位),以 0 到 240 之间的整数或浮点数表示。

高度

剪辑区域的高度(以像素为单位),以 0 到 240 之间的整数或浮点数表示。

# Restrict text and drawings to a specific region
robot.screen.set_clip_region(0, 0, 120, 120)
robot.screen.draw_rectangle(60, 60, 100, 100, RED)
robot.screen.print_at("Cut off!", x=60, y=60)

机器人的屏幕左上角显示一个红色方块,上面写着“Cut o”,停在屏幕中央。

触碰#

pressing#

pressing 返回一个布尔值,指示屏幕当前是否被按下。

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

用法:
robot.screen.pressing()

参数

描述

该方法没有参数。

# Turn LEDs white only while the screen is pressed.
while True:
    if robot.screen.pressing():
        robot.led.on(ALL_LEDS, WHITE)
    else: 
        robot.led.off(ALL_LEDS)

    wait(50, MSEC)

x_position#

x_position 返回按下屏幕的 x 坐标,以 0(左)到 240(右)之间的整数形式返回。

用法:
robot.screen.x_position()

参数

描述

该方法没有参数。

# Display the x-coordinate of where
# the screen is pressed
while True:
    if robot.screen.pressing():
        robot.screen.clear_screen()
        robot.screen.print(robot.screen.x_position())
    wait (50, MSEC)

y_position#

y_position 返回按下屏幕的 y 坐标,以 0(顶部)到 240(底部)之间的整数形式返回。

用法:
robot.screen.y_position()

# Display the y-coordinate of where
# the screen is pressed
while True:
    if robot.screen.pressing():
        robot.screen.clear_screen()
        robot.screen.print(robot.screen.y_position())
    wait (50, MSEC)

打回来#

pressed#

pressed注册了一个当机器人的屏幕被按下时调用的方法。

用法:
robot.screen.pressed(callback, arg)

参数

描述

回调

按下屏幕时将调用的方法。

arg

可选。包含调用回调方法时要传递给该方法的参数的元组。

# Set the LEDs to green when the screen is pressed.
def screen_touched():
    robot.led.on(ALL_LEDS, GREEN)

robot.screen.pressed(screen_touched)

released#

released 注册一个当屏幕不再被按下时调用的方法。

用法:
robot.screen.released(callback, arg)

参数

描述

回调

当屏幕被释放时将被调用的方法。

arg

可选。一个 tuple,包含调用回调方法时要传递给它的参数。

# Set the LEDs to blue when the screen is released.
def screen_released():
    robot.led.on(ALL_LEDS, BLUE)

robot.screen.released(screen_released)