螢幕#
介紹#
螢幕方法控制 VEX AIM 編碼機器人如何在螢幕上顯示文字、數字和圖形,以及如何回應螢幕按鍵。
以下是所有方法的清單:
觸控 – 偵測並回應螢幕按壓操作。
pressing– 返回螢幕目前是否被按下。x_position– 傳回上次畫面所按下的 x 座標。y_position– 傳回最後一次畫面按下的 y 座標。
遊標列印 – 使用行/列系統顯示文字。
print– 在目前遊標位置列印文字、數字或變數值。set_cursor– 將遊標移到指定的行和列。next_row– 將遊標移到下一行的第 1 列。clear_row– 清除一行文字。get_row– 傳回目前遊標行。get_column– 傳回目前遊標列。
XY 列印 – 在螢幕上的指定座標顯示文字。
print_at– 在指定的 x 和 y 座標處列印文字、數字或變數值。set_origin– 設定用於基於座標的列印和繪圖的原點。
變異器 – 清除螢幕或更新視覺設定。
clear_screen– 清除螢幕上的所有圖形和文字。set_font– 設定列印文字的字型。set_pen_width– 設定繪製的線條和形狀輪廓的粗細。set_pen_color– 設定文字、像素、線條和形狀輪廓的顏色。set_fill_color– 設定繪製形狀和列印文字背景的填滿顏色。
繪圖 – 在螢幕上新增圖形和影像。
draw_pixel– 在指定的 x 和 y 位置繪製像素。draw_line– 在兩點之間繪製一條線。draw_rectangle– 繪製一個長方形。draw_circle– 畫一個圓。show_file– 顯示上傳的圖像。set_clip_region– 限制圖形和文字的顯示位置。
回調函數-在螢幕被按下或釋放時運行的函數。
觸碰#
pressing#
pressing 返回一個布林值,指示機器人的螢幕目前是否被按下。
True– 螢幕被按下。False– 螢幕未按下。
用法:
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 傳回上次畫面按下的 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)
遊標列印#
print#
print 在機器人的螢幕上,於目前遊標位置和字型處列印文字、數字或變數值。
用法:robot.screen.print(text)
參數 |
描述 |
|---|---|
|
若要在螢幕上顯示的文字、數字或變數值。 |
# Display a message at the starting cursor position
robot.screen.print("Hello, Robot!")

set_cursor#
set_cursor 将文本光标移动到机器人屏幕上的指定行和列。下一次 print 调用将从该位置开始打印。能容纳的行数和列数取决于所选字体。使用默认的等宽中号字体时,屏幕最多可以清晰显示 8 行 13 列。超出此范围的文本可能会被截断或难以阅读。
等宽字体中的字符宽度均相同,因此文本布局一致。相比之下,比例字体的字符宽度各异,有些字母会占据更多空间。然而,无论使用哪种类型,set_cursor 都会根据行和列的尺寸来定位光标,而非字体样式。字体大小可以通过 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")

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

clear_row#
clear_row 清除機器人螢幕上的一行文字。
用法:robot.screen.clear_row(row, 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 傳回目前行,文字將以整數形式列印。
用法: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())

get_column#
get_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())

XY列印#
print_at#
print_at 使用当前设置的字体和原点,在机器人屏幕的指定 x 和 y 坐标处,以像素为单位,打印文本、数字或变量值。x 设置文本距离左侧的起始位置,y 设置字母底部所在的位置。此方法忽略当前光标位置。

注意:紅色圓圈標示了AIM機器人圓形螢幕上可見的座標。紅色圓圈之外的座標雖然在0-240範圍內,但不會顯示在螢幕上。
用法:
robot.screen.print_at(text, x, y)
範圍 |
描述 |
|---|---|
|
若要列印在螢幕上的文字、數字或變數值。 |
|
文字的水平位置,以 0 到 240 像素之間的整數表示。 0 為左側;240 為右側。 |
|
文字的垂直位置,以 0 到 240 像素之間的整數表示。 0 為頂部;240 為底部。 |
# Display a message in the middle of the screen
robot.screen.print_at("Hello, Robot!", x=40, y=120)

set_origin#
set_origin 設定機器人螢幕上用於繪圖和基於座標的列印的原點。預設情況下,原點位於螢幕左上角。
用法:
robot.screen.set_origin(x, y)
範圍 |
描述 |
|---|---|
|
若要設定為原點的新 x 座標,取值範圍為 0 到 240 之間的整數。 |
|
要設定的新 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 列。
用法:
robot.screen.clear_screen(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 設定用於在機器人螢幕上顯示文字的字體。此字體將套用於所有使用 print 或 print_at 列印的文字。專案開始時的預設字體為 MONO24。
用法:
robot.screen.set_font(fontname)
範圍 |
描述 |
|---|---|
|
将字体设置为以下字体之一
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
|
# Display text using a larger font
robot.screen.set_font(MONO40)
robot.screen.print("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)
範圍 |
描述 |
|---|---|
|
可选。要使用的笔和字体颜色。选项包括:
|
# 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)
範圍 |
描述 |
|---|---|
|
可选。要使用的填充色。选项包括:
|
# 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 座標處繪製一個像素。
用法:
robot.screen.draw_pixel(x, y)
範圍 |
描述 |
|---|---|
|
像素繪製位置的 x 座標,取值範圍為 0 到 240 之間的整數。 |
|
像素將被繪製的 y 座標,取值範圍為 0 到 240 之間的整數。 |
# Draw a pixel at the center of the screen
robot.screen.draw_pixel(120, 120)
![]()
draw_line#
draw_line 使用目前的 筆寬 和 筆顏色 從第一個螢幕座標 (x1, y1) 到第二個螢幕座標 (x2, y2) 繪製一條線。
x 和 y 座標使用預設原點 (0, 0),除非使用 set_origin 設定了不同的原點。
用法:
robot.screen.draw_line(x1, y1, x2, y2)
範圍 |
描述 |
|---|---|
|
直線的起始 x 座標,取值範圍為 0 到 240 的整數。 |
|
直線的起始 y 座標,取值範圍為 0 到 240 之間的整數。 |
|
直線的終點 x 座標,取值範圍為 0 到 240 之間的整數。 |
|
直線的終點 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) 坐标,大小由给定的宽度和高度决定,所有单位均为像素。矩形的轮廓使用当前的笔宽和笔颜色绘制。内部使用当前的填充色填充,除非使用了可选的 color 参数。
x 和 y 座標使用預設原點 (0, 0),除非使用 set_origin 設定了不同的原點。
用法:robot.screen.draw_rectangle(x, y, width, height, color)
範圍 |
描述 |
|---|---|
|
矩形左上角的 x 座標,取值範圍為 0 到 240 的整數。 |
|
矩形左上角的 y 座標,取值範圍為 0 到 240 的整數。 |
|
矩形的寬度,取值範圍為 0 到 240 之間的整數。 |
|
矩形的高度,取值範圍為 0 到 240 之間的整數。 |
|
可选。矩形的填充色。选项包括:
|
# Draw a red rectangle on the screen
robot.screen.draw_rectangle(50, 50, 130, 60, RED)

draw_circle#
draw_circle 绘制一个圆形,其圆心位于选定的 (x, y) 坐标,大小由给定的半径决定,所有单位均为像素。圆形的轮廓使用当前的笔宽和笔颜色绘制。内部使用当前的填充色填充,除非使用了可选的 color 参数。
x 和 y 座標使用預設原點 (0, 0),除非使用 set_origin 設定了不同的原點。
用法:robot.screen.draw_circle(x, y, radius, color)
範圍 |
描述 |
|---|---|
|
圓心的 x 座標,取值範圍為 0 到 240 之間的整數。 |
|
圓心的 y 座標,取值範圍為 0 到 240 之間的整數。 |
|
圓的半徑,取值範圍為 0 到 240 像素的整數。 |
|
可选。圆形的填充色。选项包括:
|
# Draw a green circle on the screen
robot.screen.draw_circle(120, 120, 40, GREEN)

show_file#
show_file 在機器人螢幕上顯示自訂上傳的影像,其位置根據影像的參考點,使用 x、 y和 center 參數設定。
用法:
robot.screen.show_file(file, x, y, center)
範圍 |
描述 |
|---|---|
|
要使用的自訂影像,從 |
|
影像的水平偏移量,以像素為單位的整數表示。正值向右移動影像;負值向左移動影像。 |
|
影像的垂直偏移量,以像素為單位的整數表示。正值向下移動影像;負值向上移動影像。 |
|
可選。如果 |
# 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 座標,以 0 到 240 之間的十進位數 ( |
|
裁切區域左上角的 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)

回呼函數#
pressed#
pressed 註冊一個在機器人畫面被按下時要呼叫的方法。
用法:robot.screen.pressed(callback, 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)
參數 |
描述 |
|---|---|
|
一個預先定義好的函數,當按下控制器螢幕時執行。 |
|
# Set the LEDs to blue when the screen is released.
def screen_released():
robot.led.on(ALL_LEDS, BLUE)
robot.screen.released(screen_released)










