屏幕#

介绍#

The Screen methods control how the VEX AIR Drone Controller shows text, numbers, graphics, and images on its screen, and how it responds to screen presses.

Below is a list of available methods:

Cursor Print – Display text and manage the print cursor.

  • print – Prints text, numbers, or variable values at the current cursor position.

  • set_cursor – Moves 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 row where text will be printed.

  • get_column – Returns the column where text will be printed.

XY Print – Print text at pixel-based coordinates.

  • print_at – Prints text, numbers, or variable values at a specific x and y coordinate.

  • set_origin – Sets the origin used for coordinate-based printing and drawing.

Mutators – Change screen settings, colors, and drawing behavior.

  • clear_screen – Clears all drawings, text, and images from the controller screen.

  • wait_for_render – Switches screen drawing to render-later behavior.

  • set_font – Sets the font for printed text.

  • set_pen_width – Sets the thickness of drawn lines and shape outlines.

  • set_pen_color – Sets the color of text, pixels, lines, and shape outlines.

  • set_text_fill_color – Sets the fill color behind printed text.

  • set_fill_color – Sets the fill color for drawn shapes.

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

  • draw_pixel – Draws one pixel at a specific x and y position.

  • draw_line – Draws a line between two points.

  • draw_rectangle – Draws a rectangle using the current pen and fill colors.

  • draw_circle – Draws a circle using the current pen and fill colors.

  • show_file – Draws an uploaded image.

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

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

  • x_position – Returns the x-coordinate of the last screen press.

  • y_position – Returns the y-coordinate of the last screen press.

Callbacks – Run functions when the screen is pressed or released.

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

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

光标打印#

print#

print prints text, numbers, or variable values on the controller screen at the current cursor position and font.

Usage:
controller.screen.print(text)

参数

描述

text

The text, number, or variable value to print on the screen.

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!")

VEX AIR 无人机控制器屏幕的截图,左上角有白色文字显示“是时候飞行了!”

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

与上一张截图相同,左上角文字显示为 3.14。

set_cursor#

set_cursor moves the cursor to a specific row and column on the controller screen. The next print call will start printing at that location. The row and column spacing will take into account the selected font. With the default monospaced medium font, the screen can clearly display up to 18 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

The row to move the cursor to.

column

The column to move the cursor to.

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

VEX AIR 无人机控制器屏幕的截图,屏幕中心附近有白色文字,显示“第 7 行,第 25 列”。

next_row#

next_row moves the cursor to column 1 on the next row on the controller 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")

VEX AIR 无人机控制器屏幕的截图,左上角有白色文字,第一行显示“第 1 行”,第二行紧随其后。

clear_row#

clear_row clears a row of text on the controller 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())

VEX AIR 无人机控制器屏幕的截图,屏幕中心附近有白色文字显示“7”,位于第 7 行第 25 列。

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

VEX AIR 无人机控制器屏幕的截图,屏幕中心附近有白色文字“25”,位于第 7 行第 25 列。

XY打印#

set_origin#

set_origin sets the origin (0, 0) used for drawing and coordinate-based printing on the controller screen. By default, the origin is the top-left corner of the screen. 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)

VEX AIR 无人机控制器屏幕的截图,绘制了一个白色矩形,使左上角位于屏幕中心。

修改器#

clear_screen#

clear_screen clears all drawings, text, and images from the controller screen.

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

范围

描述

row

Optional. The row to move the cursor to after clearing the screen. The default is 1.

col

Optional. The column to move the cursor to after clearing the screen. The default is 1.

color

Optional. Sets the screen color. If row and col are included, use color as the third argument. 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(color=RED)

wait_for_render#

wait_for_render switches screen drawing to render-later behavior. Once this method runs, following screen commands will not appear on the controller screen until the next wait_for_render method runs.

Note: Use this before drawing a group of text, shapes, or images, then use it again to render the full update at once.

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

VEX AIR 无人机控制器屏幕的截图,左上角有白色文字“屏幕渲染完成!”,屏幕中央画有一个白色圆圈。

set_font#

set_font sets the font used for displaying text on the controller screen. This font will apply to all text printed after this method runs. 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

这是一张VEX AIR无人机控制器屏幕的截图,左上角用Mono 12字体打印着一些白色字母和数字。字母AZ在一行,占据了屏幕大约三分之一的宽度。左下角显示着91个字符,30行。
MONO12

与上一张图相同,但这次使用了 Mono 15 字体。字母 AZ 位于一行,占据了屏幕近一半的宽度。左下角显示“71 个字符,23 行”。
MONO15

与上一张图相同,但这次使用了 Mono 20 字体。字母 AZ 位于一行,占据屏幕宽度的一半。左下角显示“53 个字符,18 行”。
MONO20

与上一张图相同,但这次使用了 Mono 24 字体。字母 AZ 位于一行,占据屏幕宽度的一半多一点。左下角显示“45 个字符,15 行”。
MONO24

与上一张图相同,但这次使用了 Mono 30 字体。字母 AZ 位于一行,占据了屏幕宽度的大约四分之三。左下角显示“35 个字符,12 行”。
MONO30

与上一张图相同的图像,现在使用了 Mono 36 字体。字母 AZ 位于一行,几乎横跨整个屏幕宽度。左下角显示 29 个字符宽,10 行高。
MONO36

与上一张图相同的图像,现在使用了 Mono 40 字体。字母 AZ 位于一行,横跨屏幕宽度。左下角显示 26 个字符,共 9 行。
MONO40

与上一张图相同,但这次使用了 Mono 60 字体。字母 AQ 位于一行,横跨屏幕宽度。左下角显示 17 个字符,共 6 行。
MONO60

与上一张图相同,但这次使用了 Prop 20 字体。字母 AZ 位于一行,占据了屏幕宽度的一半多一点。左下角显示“49 个字符,18 行”。
PROP20

与上一张图相同,但这次使用了24号提案字体。字母AZ在一行,占据了屏幕宽度的大约三分之二。左下角显示“42个字符,15行”。
PROP24

与上一张图相同,但这次使用了 Prop 30 字体。字母 AZ 位于一行,占据了屏幕宽度的四分之三。左下角显示“33 个字符,12 行”。
PROP30

与上一张图相同,但这次使用了36号提案字体。字母AZ位于一行,几乎横跨整个屏幕宽度。左下角显示一行共27个字符,10行。
PROP36

与上一张图相同,但这次使用了 Prop 40 字体。字母 AY 位于一行,横跨屏幕宽度。左下角显示“24 个字符,9 行”。
PROP40

与上一张图相同,但这次使用了 Prop 60 字体。字母 AQ 位于一行,横跨屏幕宽度。左下角显示一行共 17 个字符,6 行。
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 thickness of drawn lines and shape outlines.

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)

VEX AIR 无人机控制器屏幕的截图,中间印有一个带粗边框的白色矩形。

set_pen_color#

set_pen_color sets the color of text, pixels, lines, and shape outlines.

Usage:
controller.screen.set_pen_color(color)

范围

描述

color

Optional. Sets the pen and font 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)

VEX AIR 无人机控制器屏幕的截图,中间有一个细长的橙色矩形,矩形内印有白色的“VEXcode AIR”字样。

set_text_fill_color#

set_text_fill_color sets the fill color behind printed text. The default text fill color is transparent.

Usage:
controller.screen.set_text_fill_color(color)

范围

描述

color

Optional. Sets the text fill 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")

VEX AIR 无人机控制器屏幕的截图,左上角打印了两行文字。第一行是白色字体的“红色”,并以红色高亮显示;第二行紧随其后,是白色字体的“蓝色”,并以蓝色高亮显示。

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)

VEX AIR 无人机控制器屏幕的截图,图中有一个实心橙色矩形,四周有细细的白色边框,矩形中央印有白色文字“VEXcode AIR”。

#

draw_pixel#

draw_pixel draws one pixel at the selected x and y coordinate using the current 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)

VEX AIR 无人机控制器屏幕的截图,屏幕中央沿对角线均匀地印有 5 个像素。

draw_line#

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

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)

VEX AIR 无人机控制器屏幕的截图,从左上角到右下角画一条白线,从左下角到右上角画一条青色线,两条线在中心相交。

draw_rectangle#

draw_rectangle draws a rectangle using the current pen width, pen color, and fill color, unless the optional color parameter is used.

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)

VEX AIR 无人机控制器屏幕的截图,屏幕中心印有一个带有细白边框的实心绿色矩形,屏幕外缘印有一个细白边框。

draw_circle#

draw_circle draws a circle using the current pen width, pen color, and fill color, unless the optional color parameter is used.

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:

  • BLACK
  • 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)

VEX AIR 无人机控制器屏幕的截图,屏幕中央绘制了一个带有细白边框的大型实心绿色圆圈。

show_file#

show_file draws a custom uploaded image on the controller screen at an x and y position, with optional scaling, rotation, and alpha transparency.

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

范围

描述

file

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

x

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

y

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

scale_width

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

scale_height

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

rotation

Optional. The number of degrees to rotate the image, given as an integer from 0 to 359.

use_alpha

Optional. Whether to use the image’s alpha channel for transparency. Options include: True or 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 a Boolean indicating whether the robot’s screen is currently being pressed.

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

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

x_position#

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

A VEX AIR Drone Controller with the printable area of the screen dimensions labeled and outlined in a red box. The coordinates begin with (0,0) in the upper left corner, and proceed clockwise with (0, 640), (480, 640), and (480,0) to the lower left corner. The center coordinates of the screen are labeled (240, 320).

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 last pressed, as an integer from 0 (top) to 480 (bottom).

A VEX AIR Drone Controller with the printable area of the screen dimensions labeled and outlined in a red box. The coordinates begin with (0,0) in the upper left corner, and proceed clockwise with (0, 640), (480, 640), and (480,0) to the lower left corner. The center coordinates of the screen are labeled (240, 320).

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)

Callbacks#

pressed#

pressed registers a function to be called when the controller screen is pressed.

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

参数

描述

callback

A function that is previously defined to execute when the controller screen is pressed.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

# 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 function to be called when the controller screen is released.

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

参数

描述

callback

A function that is previously defined to execute when the controller screen is released.

arg

Optional. A tuple containing arguments to pass to the callback function. See Using Functions with Parameters for more information.

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

controller.screen.released(play_sound)