屏幕#

介绍#

VEX AIM 编码机器人的屏幕提供了显示文本、管理光标、绘制形状和处理触摸交互的方法。

以下是所有方法的列表:

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

  • print – Prints text at the current cursor position.

  • set_cursor – Sets the cursor to a specific row and column.

  • next_row – Moves the cursor to column 1 of the next row.

  • clear_row – Clears a row of text.

  • get_row – Returns the current cursor row.

  • get_column – Returns the current cursor column.

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

  • print_at – Prints text at a specific x and y location.

  • set_origin – Sets a new origin for printing and drawing.

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

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

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

  • x_position – Returns the x-coordinate where the screen is pressed.

  • y_position – Returns the y-coordinate where the screen is pressed.

  • pressing – Returns whether the screen is currently being pressed.

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

  • pressed – Registers a function to call when the screen is pressed.

  • released – Registers a function to call when the screen is released.

光标打印#

print#

print displays text on the robot’s screen at the current cursor position and font.

Usage:
robot.screen.print(text)

参数

描述

text

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

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

机器人屏幕的截图,顶部用白色字体打印着“你好,机器人!”。

set_cursor#

set_cursor places the text cursor at a specific row and column on the screen. The number of rows and columns that fit depends on the selected font. With the default monospaced medium font, the screen can clearly display up to 8 rows and 13 columns. Text placed beyond this range may be cut off or harder 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, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using set_font.

Usage:
robot.screen.set_cursor(row, column)

参数

描述

row

游标所在行。

column

光标所在的列。

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

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

next_row#

next_row moves the cursor to column 1 on the next row on the robot’s screen.

Usage:
robot.screen.next_row()

参数

描述

该方法没有参数。

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

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

clear_row#

clear_row clears a row of text on the robot’s screen.

Usage:
robot.screen.clear_row(row, color)

范围

描述

row

可选。要清除的行号,以整数形式表示。默认值为当前光标所在行。

color

Optional. The color to apply to the cleared row. Options include:

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

# 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)

机器人屏幕的截图,屏幕中央从左到右有一条绿色横条。

get_row#

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

Usage:
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())

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

get_column#

get_column returns the current column where text will be printed as an integer.

Usage:
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())

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

XY打印#

set_origin#

set_origin 方法用于设置机器人屏幕上绘图或打印的原点 (0, 0)。默认情况下,绘图或打印方法将屏幕左上角作为原点。此方法可以将原点重置为屏幕坐标系中的其他位置 (x, y)。

Usage:
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 clears all drawings and text from the robot’s screen. By default, it also resets the cursor position to row 1, column 1.

Usage:
robot.screen.clear_screen(color)

范围

描述

color

Optional. Sets the screen color. Options include:

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

# 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 sets the font used for displaying text on the robot’s screen. This font will apply to all text printed with print or print_a. The default font at the start of a project is MONO24.

Usage:
robot.screen.set_font(fontname)

范围

描述

fontname

Sets the font to one of the following:

  • MONO12
  • MONO15
  • MONO20
  • MONO24
  • MONO30
  • MONO40
  • MONO60
  • PROP20
  • PROP30
  • PROP40
  • PROP60
These options are shown below.

这是一张机器人屏幕的截图,显示了以 Mono 12 字体打印的数字和字母示例。字母占据一行文本。底部文字横向 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。字母 AH 占据一行文字。底部文字为 8 个字符,共 5 行。
MONO40

与上一张图片相同,数字以 Mono 60 字体印刷。数字 1-6 占据一行文字。底部文字共三行。
MONO60

与上一张图相同,但字体为20号提案字体。字母“As”占据一行文字。底部文字为20个字符宽,共9行。
PROP20

与上一张图相同,但字体为Prop 30字体。字母AM占据一行文字。底部文字横向15个字符,共6行。
PROP30

与上一张图相同,但字体为Prop 40字体。字母AJ占据一行文字。底部文字横向11个字符,共5行。
PROP40

与上一张图相同,数字以 Prop 60 字体印刷。数字 1-7 占据一行文字。底部文字为 7 x 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 设置用于绘制线条和形状的笔的宽度。

Usage:
robot.screen.set_pen_width(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 设置用于绘制线条、形状和文本的画笔颜色。

Usage:
robot.screen.set_pen_color(color)

范围

描述

color

Optional. Sets the pen color. Options include:

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

# 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 方法设置绘制形状时使用的填充颜色。

Usage:
robot.screen.set_fill_color(color)

范围

描述

color

Optional. Sets the fill color. Options include:

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

# 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 draws a pixel at the specified (x, y) screen coordinate in the current pen color. It uses the current pen color set by set_pen_color.

Usage:
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.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

Usage:
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 draws a rectangle with its top-left corner at the specified (x, y) coordinate and a size determined by the given width and height, all measured in pixels. The rectangle’s outline is drawn using the current pen width set by set_pen_width and the pen color set by set_pen_color. The interior is filled with the color set by set_fill_color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

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

范围

描述

x

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

y

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

width

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

height

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

color

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)

机器人屏幕的截图,屏幕上半部分居中显示一个亮红色矩形,矩形边缘有一条细细的白色边框。

draw_circle#

draw_circle draws a circle with its center at the specified (x, y) coordinate and a size determined by the given radius, all measured in pixels. The circle’s outline is drawn using the current pen width set by set_pen_width and the pen color set by set_pen_color. The interior is filled with the color set by set_fill_color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

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

范围

描述

x

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

y

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

radius

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

color

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

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

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

机器人屏幕的截图,中心有一个亮绿色圆圈,圆圈边缘有细细的白色边框。

show_file#

show_file displays a custom uploaded image on the robot’s screen, with its position set using the x, y, and center parameters based on the image’s reference point.

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

范围

描述

file

The custom image to use, from IMAGE1 to IMAGE10. The image number matches the number shown in the AIM control panel.

x

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

y

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

center

Optional. If center=True, the image is placed using its center at coordinate (120, 120). By default (center=False), the top-left corner of the image is used and positioned relative to the current origin.

# 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 defines a rectangular area on the screen where all drawings and text will be confined. Any content outside this region will not be displayed.

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

范围

描述

x

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

y

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

width

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

height

剪辑区域的高度(以像素为单位),以 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 returns a Boolean indicating whether the screen is currently being pressed.

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

Usage:
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)

# Display different messages after the screen is pressed
while not robot.screen.pressing():
    wait(5, MSEC)
robot.screen.print("First message!")
robot.screen.next_row()
# Lift finger to press the screen again
while robot.screen.pressing():
    wait(5, MSEC)
while not robot.screen.pressing():
    wait(5, MSEC)
robot.screen.print("Second message!")
robot.screen.next_row()

x_position#

x_position returns the x-coordinate where the screen is pressed as an integer from 0 (left) to 240 (right).

Usage:
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 returns the y-coordinate where the screen is pressed as an integer from 0 (top) to 240 (bottom).

Usage:
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 registers a method to be called when the robot’s screen is pressed.

Usage:
robot.screen.pressed(callback, arg)

参数

描述

callback

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

arg

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

# 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 registers a method to be called when the screen is no longer being pressed.

Usage:
robot.screen.released(callback, arg)

参数

描述

callback

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

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)