屏幕#

介绍#

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

以下是所有可用方法的列表:

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

  • 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.

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

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

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

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

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

  • y_position – Returns the y-coordinate where the screen is 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 controller’s screen at the current cursor position and font.

Usage:
controller.screen.print(text)

参数

描述

text

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

sep

Optional. The separator between printed text. By default, sep = ’ ‘

end

Optional. The string appended after the last printed text. By default, end = ‘\n’

precision

Optional. The number of decimals a float will print with as an integer. By default, precision = 5

# Display a message at the starting cursor position.
controller.screen.print("Time to fly!")

显示 drone.screen.print 方法,并显示“Time to Fly!”

# Display the first 2 decimals of pi
controller.screen.print(3.1415, precision = 2)

显示 drone.screen.print 方法,其中 pi 精确到小数点后 2 位

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 11 rows and 53 columns. Text placed beyond this range may be cut off or harder to read.

Usage:
controller.screen.set_cursor(row, col)

参数

描述

row

游标所在行。

column

光标所在的列。

# Display text starting at Row 7 Column 25.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print("Row 7, Column 25")

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

next_row#

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

Usage:
controller.screen.next_row()

参数

描述

该方法没有参数。

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

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

clear_row#

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

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

范围

描述

row

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

color

Optional. The color to apply to the cleared row. If a color is not specified, the set_fill_color is used. Options include:

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

# Clear only the second row of text
controller.screen.print("This text stays")
controller.screen.next_row()
controller.screen.print("This text disappears")
wait(3, SECONDS)
controller.screen.clear_row(2)

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

get_row#

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

Usage:
controller.screen.get_row()

参数

描述

该方法没有参数。

# Display the cursor's current row.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_row())

当您将 curSor 设置为 7,25 时,通过显示列号 7 来显示 drone.screen.print_at 方法

get_column#

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

Usage:
controller.screen.get_column()

参数

描述

该方法没有参数。

# Display the cursor's current column.
controller.screen.set_cursor(row=7, col=25)
controller.screen.print(controller.screen.get_column())

当您将 curSor 设置为 7,25 时,通过显示列号 25 来显示 drone.screen.print_at 方法

XY打印#

set_origin#

set_origin sets the origin (0, 0) used for drawing or printing on the controller’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.

Usage:
controller.screen.set_origin(x, y)

范围

描述

x

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

y

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

# Set the origin to the center of the screen.
controller.screen.set_origin(x=320, y=240)

# Draw a rectangle at the new origin.
controller.screen.draw_rectangle(x=0, y=0, width=80, height=40)

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

修改器#

clear_screen#

clear_screen clears the controller’s screen of all drawings, text, and images.

Usage:
controller.screen.clear_screen(row, col, color)

范围

描述

row

可选。清除屏幕后光标的 x 位置。默认值为 1。

col

可选。清除屏幕后光标的 y 位置。默认值为 1。

color

Optional. Sets the screen color. To use, you must include all three optional parameters. 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.
controller.screen.draw_circle(x=320, y=240, radius=80)
wait(2, SECONDS)
controller.screen.clear_screen()

# Print two messages in the same spot
controller.screen.print("Hello!")
wait(3,SECONDS)
controller.screen.clear_screen(row=1, col=1)
controller.screen.print("Goodbye!")

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

wait_for_render#

wait_for_render prevents any following commands from running until all previous drawing and print commands on the screen have finished rendering.

Usage:
controller.screen.wait_for_render()

范围

描述

该方法没有参数。

# Display text and images when button 7 is pressed.
controller.screen.wait_for_render()
controller.screen.print("Screen rendered!")
controller.screen.draw_circle(x=320, y=240, radius=80)
while not controller.button7.pressing():
    wait(5, MSEC)
controller.screen.wait_for_render()

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

set_font#

set_font sets the font used for displaying text on the controller’s screen. This font will apply to all text printed with print or print_at. The default font at the start of a project is MONO20.

Usage:
controller.screen.set_font(fontname)

范围

描述

fontname

Sets the font to one of the following:

  • MONO12
  • MONO15
  • MONO20
  • MONO24
  • MONO30
  • MONO36
  • MONO40
  • MONO60
  • PROP20
  • PROP24
  • PROP30
  • PROP36
  • PROP40
  • PROP60

控制器屏幕打印了MONO 12字体的数字和字母,屏幕底部横排90行,共37行。
MONO12

控制器屏幕打印了MONO 15字体的数字和字母。屏幕底部有70个横排和28行。
MONO15

控制器屏幕打印了MONO 20字体的数字和字母。屏幕底部有52个横排和22行。
MONO20

控制器屏幕打印了MONO 24字体的数字和字母。屏幕底部有44个横排和18行。
MONO24

控制器屏幕打印了MONO 30字体的数字和字母。屏幕底部有34个横排和14行。
MONO30

控制器上丝印了MONO 36字体的数字和字母,屏幕底部为28行12列。
MONO36

控制器屏幕打印了MONO 40字体的数字和字母。屏幕底部有25个横排和11行。
MONO40

控制器屏幕打印了MONO 60字体的数字和字母。屏幕底部有16个横排7行的字体。
MONO60

控制器上丝网印刷了PROP 20字体的数字和字母。屏幕底部有58个横排和22行。
PROP20

控制器上丝网印刷了PROP 24字体的数字和字母。屏幕底部,横排45行,共18行。
PROP24

控制器上丝网印刷了PROP 30字体的数字和字母。屏幕底部有37个横排和14行。
PROP30

控制器上丝网印刷了PROP 36字体的数字和字母。屏幕底部有30个横排和12行。
PROP36

控制器上丝网印刷了PROP 40字体的数字和字母。屏幕底部有28个横排,11行。
PROP40

控制器上丝网印刷了PROP 60字体的数字和字母。屏幕底部有19个横排和7行。
PROP60

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

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

set_pen_width#

set_pen_width sets the pen width used for drawing lines and shapes.

Usage:
controller.screen.set_pen_width(width)

范围

描述

width

笔的宽度,以像素为单位的整数表示。

# Draw a rectangle with a pen width of 10.
controller.screen.set_pen_width(10)
controller.screen.draw_rectangle(x=200, y=200, width=200, height=80)

控制器的屏幕显示一个带有粗边框的矩形。

set_pen_color#

set_pen_color sets the pen color used for drawing lines, shapes, and printing text.

Usage:
controller.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 an orange outline.
controller.screen.set_pen_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=240, height=150)
controller.screen.set_pen_color(WHITE)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

控制器的屏幕显示一个带有细边框的橙色矩形,其中心显示白色的 VEXcode AIR。

set_text_fill_color#

set_text_fill_color sets the highlight color used when text is printed. The default highlight color is transparent.

Usage:
controller.screen.set_text_fill_color(color)

范围

描述

color

Optional. Sets the text highlight color. Options include:

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

# Display two colors behind text
controller.screen.set_text_fill_color(RED)
controller.screen.print("Red")
controller.screen.next_row()
controller.screen.set_text_fill_color(BLUE)
controller.screen.print("Blue")

控制器的屏幕显示两行“红色”和“蓝色”,并以相应的颜色突出显示文本。

set_fill_color#

set_fill_color sets the fill color used when shapes are drawn. The default fill color is black.

Usage:
controller.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 an orange-filled rectangle with text on top
controller.screen.set_fill_color(ORANGE)
controller.screen.draw_rectangle(x=200, y=150, width=250, height=150)
controller.screen.print_at("VEXcode AIR", x=250, y=220)

控制器的屏幕显示一个白色边框的橙色矩形,边框很细,中间是白色的 VEXcode AIR。

#

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:
controller.screen.draw_pixel(x, y)

范围

描述

x

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

y

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

# Draw five pixels in a diagonal.
controller.screen.draw_pixel(x=360, y=200)
controller.screen.draw_pixel(x=340, y=220)
controller.screen.draw_pixel(x=320, y=240)
controller.screen.draw_pixel(x=300, y=260)
controller.screen.draw_pixel(x=280, y=280)

控制器的屏幕上显示一行五个白色像素。

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:
controller.screen.draw_line(x1, y1, x2, y2)

范围

描述

x1

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

y1

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

x2

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

y2

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

# Make an X across the screen.
controller.screen.draw_line(x1=0, y1=0, x2=640, y2=480)
controller.screen.set_pen_color(CYAN)
controller.screen.draw_line(x1=0, y1=480, x2=640, y2=0)

控制器的屏幕在中心显示一个 X。

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:
controller.screen.draw_rectangle(x, y, width, height, color)

范围

描述

x

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

y

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

width

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

height

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

color

Optional. Sets 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 two rectangles on the screen.
controller.screen.draw_rectangle(x=0, y=0, width=620, height=460)
controller.screen.draw_rectangle(x=200, y=180, width=200, height=100, color=GREEN)

控制器的屏幕显示一个绿色矩形,带有一条细白边框,周围环绕着一个较大的带白边框的矩形。

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:
controller.screen.draw_circle(x, y, radius, color)

范围

描述

x

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

y

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

radius

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

color

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

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

# Draw one green circle on the screen.
controller.screen.set_fill_color(GREEN)
controller.screen.draw_circle(x=320, y=240, radius=200, color=GREEN)

控制器的屏幕显示一个绿色圆圈,中间画有一条细白边框。

show_file#

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

Usage:
controller.screen.show_file(file, x, y, scale_width, scale_height, rotate, use_alpha)

范围

描述

file

要使用的用户上传的图片。如果在控制面板中编辑了图片名称,选项将会更改。

x

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

y

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

scale_width

可选。要缩放的图像宽度,以像素为单位的整数形式给出。

scale_height

可选。要缩放的图像高度,以像素为单位的整数形式给出。

rotation

可选。图像旋转的度数,以 0 到 359 之间的整数表示。

use_alpha

Optional. Use alpha channel for image to show transparent. Options include:

  • True
  • False

# Display uploaded Image 1 in the top left corner.
controller.screen.show_file(IMAGE1, x=0, y=0)

# Display uploaded Image 1 scaled to the full screen.
controller.screen.show_file(IMAGE1, x=65, y=0, scale_width=640, scale_height=480)

# Display uploaded Image 1 with rotation of 180 degrees.
controller.screen.show_file(IMAGE1, x=-65, y=0, rotation=180)

# Upload an image with a transparent background.
# Display uploaded Image 1 with alpha channel enabled.
controller.screen.show_file(IMAGE1, x=0, y=0, use_alpha=True)

触碰#

pressing#

pressing returns whether the controller’s screen is currently being pressed as a Boolean:

  • True – The screen is being pressed.

  • False – The screen is not being pressed.

Usage:
controller.screen.pressing()

参数

描述

该方法没有参数。

# Play a sound when the screen is pressed.
while True:
    if controller.screen.pressing():
        controller.sound.play_note("C5", 500)
    wait(5, MSEC)

x_position#

x_position returns the x-coordinate in pixels where the screen was pressed, as an integer from 0 (left) to 640 (right).

VEX AIR 控制器已开启并朝前。屏幕尺寸列在屏幕边框上高亮的红色方框边缘。左上角为 (0, 0),右上角为 (640, 0),左下角为 (0, 480),右下角为 (640, 480),中心为 (320, 240)。

Usage:
controller.screen.x_position()

参数

描述

该方法没有参数。

# Play a high or low note based on where screen is pressed.
while True:
    if controller.screen.pressing():
        if controller.screen.x_position() > 320:
            controller.sound.play_note("C6", 500)
        else:
            controller.sound.play_note("C4", 500)
    wait(5, MSEC)

y_position#

y_position returns the y-coordinate in pixels where the screen was pressed, as an integer from 0 (top) to 480 (bottom).

VEX AIR 控制器已开启并朝前。屏幕尺寸列在屏幕边框上高亮的红色方框边缘。左上角为 (0, 0),右上角为 (640, 0),左下角为 (0, 480),右下角为 (640, 480),中心为 (320, 240)。

Usage:
controller.screen.y_position()

# Play a high or low note based on where screen is pressed.
while True:
    if controller.screen.pressing():
        if controller.screen.y_position() > 240:
            controller.sound.play_note("C6", 500)
        else:
            controller.sound.play_note("C4", 500)
    wait(5, MSEC)

打回来#

pressed#

pressed registers a method to be called when the controller’s screen is pressed.

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

参数

描述

callback

先前定义的 函数,当轴的值发生变化时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数

# Play a sound when the screen is pressed.
def play_sound():
    controller.sound.play_note("C5", 500)

controller.screen.pressed(play_sound)

released#

released registers a method to be called when the screen is no longer being pressed.

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

参数

描述

callback

先前定义的 函数,当轴的值发生变化时执行。

arg

可选。包含要传递给回调函数的参数的元组。有关更多信息,请参阅使用带参数的函数

# Play a sound when the screen is pressed.
def play_sound():
    controller.sound.play_note("C5", 500)
    
controller.screen.released(play_sound)