螢幕#

介紹#

screen 類別衍生自 brain 基底類別。它控制 IQ(第二代)大腦如何在其內建螢幕上顯示文字、數字和圖形。

預設情況下,印到大腦的字體是等寬小號。

大腦的繪圖解析度為 160 x 108 像素。

使用權#

可以透過以下方式存取 screen 類:

Brain.Screen

筆記#

  • The screen object is provided by the Brain. It is not constructed directly.

  • 項目使用單一全域 Brain 對象,因此螢幕函數使用 Brain.Screen呼叫。

例子#

/* This constructor is required when using VS Code.
A Brain is generated automatically at the start of
VEXcode projects. */

// Create the Brain
brain Brain = brain();

// Print text to the Brain screen
Brain.Screen.print("Hello!");

成員功能#

screen 類別包含以下成員函數:

  • print — 將格式化的文字、數字或布林值列印到 Brain 畫面。

  • setCursor — 將文字遊標移到指定的行和列。

  • newLine — 清除目前行的剩餘內容並將遊標移至下一行。

  • clearLine — 清除目前行的剩餘部分或清除指定的行。

  • row — 傳回要列印文字的行。

  • column — 傳回要列印文字的列。

  • getStringHeight — 使用目前字體傳回字串的像素高度。

  • getStringWidth — 使用目前字體傳回字串的像素寬度。

  • printAt — 在 x, y 像素位置列印格式化文字(可選不透明)。

  • clearScreen — 清除整個畫面(可選擇清除為指定顏色)。

  • setFont — 設定用於螢幕列印的字型。

  • setPenWidth — 設定繪製的線條和形狀輪廓的粗細。

  • setPenColor — 設定文字、像素、線條和形狀輪廓的顏色。

  • setFillColor — 設定繪製形狀和列印文字背景的填滿顏色。

  • setOrigin — 設定螢幕座標的原點。

  • setClipRegion — 將螢幕輸出限制在長方形區域內。

  • drawPixel — 在座標處繪製一個像素。

  • drawLine — 在兩點之間畫一條線。

  • drawRectangle — 在 x, y 位置繪製一個指定大小的矩形。

  • drawCircle — 在 x, y 位置繪製一個具有指定半徑的圓。

  • drawImageFromFile — 將 SD 卡檔案中的影像繪製到螢幕上。

  • render — 啟用雙緩衝或將後緩衝區渲染到螢幕。

  • pressing — 返回螢幕目前是否被按下。

  • xPosition — 傳回最近一次畫面按下的 x 座標。

  • yPosition — 傳回最近一次畫面按下的 y 座標。

  • pressed — 註冊一個在螢幕被按下時運行的回呼函數。

  • released — 註冊一個回呼函數,當螢幕被按下後釋放時運行。

在呼叫任何 screen 成員函數之前,必須建立一個 brain 實例,如下所示:

// Create the Brain
brain Brain = brain();

print#

在 IQ(第二代)大腦螢幕上顯示文字、數字或布林值。

Available Functions

1 — 使用字串字面量或唯讀 C 風格字串列印格式化文字。

void print(
    const char* format,
    ... );

2 — 使用可修改的字元陣列列印格式化文字。

void print(
    char* format,
    ... );

Parameters

範圍

類型

描述

format

const char*

以字串字面量或唯讀 C 風格字串形式提供的格式字串(例如, “Score: %d”)。

format

char*

以可修改字元數組形式提供的格式字串。

…

插入到格式字串中的一個或多個附加價值,以逗號分隔。

Return Values

此函數不傳回值。

Notes Examples
// Display a message at the starting cursor
Brain.Screen.print("Hello, Robot!");

IQ(第二代)大腦的螢幕截圖,顯示螢幕左上角以白色文字列印著「Hello, Robot!」。

setCursor#

將遊標移到 IQ(第二代)Brain 螢幕上的特定行和列。下一次 print 呼叫將從該位置開始列印。

Available Functions
void setCursor(
  int32_t row, 
  int32_t col );

Parameters

範圍

類型

描述

row

int32_t

要將遊標移到的行。

col

int32_t

要將遊標移到的列。

Return Values

此函數不傳回值。

Notes
  • 影響使用 print 時後續文字輸出的起始位置。

  • 行和列基於目前設定的螢幕字體。

  • 預設字體(mono20)使用 5 行 16 列。

  • 呼叫 setCursor 只會影響後續文字輸出的位置。

Examples
int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Repeatedly print the Brain timer at top-left
  while (true) {
    Brain.Screen.print("%d", Brain.Timer.time(seconds));
    Brain.Screen.newLine();
    wait(1, seconds);
    Brain.Screen.clearScreen();
    Brain.Screen.setCursor(1, 1);
  }
}

IQ(第二代)大腦的螢幕截圖,顯示螢幕左上角列印著數字 25。

newLine#

將遊標移到大腦螢幕上下一行的開頭。

Available Functions
void newLine();

Parameters

此函數不接受任何參數。

Return Values

此函數不傳回值。

Notes
  • 如果遊標位於句子的中間,則 newLine 將清除遊標之後的行的其餘部分,然後再移至下一行。

  • 呼叫 newLine後,遊標位於下一行的第一列。

  • 使用 setCursor 設定遊標位置和行號。

Examples
// Display two lines of text
Brain.Screen.print("Line 1");
Brain.Screen.newLine();
Brain.Screen.print("Line 2");

IQ(第二代)大腦螢幕的截圖,左上角顯示兩行白色文字。上面一行是“第 1 行”,緊鄰它的第二行是“第 2 行”。

clearLine#

清除 IQ(第二代)大腦螢幕上某一行的文字。

Available Functions

1 — 清除遊標位置的目前行剩餘內容。

void clearLine();

2 — 使用目前配置的 填滿顏色 清除指定的行。

void clearLine(
    int number );

3 — 使用預先定義或 自訂顏色 物件清除指定的行。

void clearLine(
    int          number,
    const color& color );

4 — 使用十六進位顏色值清除指定的行。

void clearLine(
    int         number,
    const char* color );

5 — 使用色調值清除指定的行。

void clearLine(
    int number,
    int hue );

Parameters

範圍

類型

描述

number

int

要清除的行號。行號從 1開始。

color

const color&

使用 color 对象清除行。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
这也可以使用自定义颜色对象。

color

const char*

使用十六進位顏色值清除行(例如, “#000000”)。

hue

int

使用 0–359範圍內的整數色調值清除行,表示色輪上的度數。

Return Values

此函數不傳回值。

Notes
  • 清除一行不會改變目前遊標位置。

  • 使用 setCursor 設定遊標位置和行號。

  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
// Display text on two rows
Brain.Screen.print("This text stays");
Brain.Screen.newLine();
Brain.Screen.print("This disappears");

// Wait 3 seconds before clearing row 2
wait(3, seconds);
Brain.Screen.clearLine(2);

row#

返回 IQ(第二代)Brain 螢幕上將列印文字的行。

Available Functions
int32_t row();

Parameters

此函數不接受任何參數。

Return Values

傳回 int32_t ,表示要列印文字的行。

行號從1開始。

Notes
  • 遊標位置基於 螢幕字體。

  • 返回值指示下一個列印輸出將顯示在哪裡。

  • 當列印文字或呼叫 setCursor 時,行值會改變。

Examples
// Display the cursor's current row
Brain.Screen.setCursor(3, 12);
Brain.Screen.print("row: ", Brain.Screen.row());

IQ(第二代)大腦螢幕的螢幕截圖,顯示螢幕左側第 3 行第 12 列位置的白色文字「第 3 行」。

column#

返回 IQ(第二代)大腦螢幕上將列印文字的列。

Available Functions
int32_t column();

Parameters

此函數不接受任何參數。

Return Values

傳回 int32_t ,表示要列印文字的列。

列編號從 1 開始。

Notes
  • 遊標位置基於 螢幕字體。

  • 返回值指示下一個列印輸出將顯示在哪裡。

  • 當列印文字或呼叫 setCursor 時,列值會改變。

Examples
// Display the cursor's current column
Brain.Screen.print("column: ", Brain.Screen.column());

IQ(第二代)大腦螢幕的螢幕截圖,顯示螢幕頂部第 1 行第 9 列的白色數字:9。

getStringHeight#

傳回字串在 IQ(第二代)Brain 螢幕上渲染時的高度(以像素為單位)。

Available Functions
int32_t getStringHeight( 
    const char* cstr );

Parameters

範圍

類型

描述

cstr

const char*

要測量的文本,以 C 風格字串 的形式提供(例如, “Hello”)。

Return Values

傳回 int32_t ,表示字串在 Brain 螢幕上渲染時的像素高度。

Notes
  • 返回的高度取決於目前選定的螢幕 。

  • 此函數測量字串的長度,但不將其繪製到螢幕上。

  • 傳回的高度反映了字串列印時的外觀。

getStringWidth#

傳回字串在 IQ(第二代)Brain 螢幕上渲染時的寬度(以像素為單位)。

Available Functions
int32_t getStringWidth( 
    const char* cstr );

Parameters

範圍

類型

描述

cstr

const char*

要測量的文本,以 C 風格字串 的形式提供(例如, “Hello”)。

Return Values

傳回 int32_t ,表示字串在 Brain 螢幕上渲染時的像素寬度。

Notes

printAt#

在 IQ(第二代)大腦螢幕上的特定座標處列印文字、數字或布林值。

Available Functions

1 — 在指定的像素位置列印格式化的輸出。

void printAt(
    int32_t    x,
    int32_t    y,
    const char* format,
    ... );

2 — 在指定的像素位置列印格式化的輸出,並設定文字背景是不透明還是透明。

void printAt(
    int32_t    x,
    int32_t    y,
    bool       bOpaque,
    const char* format,
    ... );

Parameters

範圍

類型

描述

x

int32_t

列印位置的 x 座標,以螢幕原點為參考。

y

int32_t

列印位置的 y 座標,以螢幕原點為參考。

bOpaque

bool

Controls whether the printed text is drawn opaquely or transparently:

  • true — The background of the printed text is filled using the current fill color.
  • false — The text is drawn transparently and the background is not filled.

format

const char*

控制螢幕上列印內容的格式字串(例如, “Score: %d”)。

…

插入到格式字串中的一個或多個附加價值,以逗號分隔。

Return Values

此函數不傳回值。

Notes
  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行更改。

  • 列印文字使用 螢幕字體。

  • 列印文字使用 筆顏色。

  • 使用格式字串時,傳遞的值的數量和類型必須與字串中的 格式說明符 相符。

Examples
// Print the number 1 at pixel (100, 40)
Brain.Screen.printAt(100, 40, 1);

IQ(第二代)大腦螢幕的截圖,白色文字顯示為 1,列印位置為 (100, 40)。

clearScreen#

清除大腦螢幕上的所有圖畫和文字。

Available Functions

1 — 將螢幕清空至黑色。

void clearScreen();

2 — 使用預先定義或 自訂顏色 物件清除螢幕。

void clearScreen(
    const color& color );

3 — 使用十六進位顏色值清除螢幕。

void clearScreen(
    const char* color );

4 — 使用色調值清除螢幕。

void clearScreen(
    int hue );

Parameters

範圍

類型

描述

color

const color&

使用 color 对象清除屏幕。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
也可以使用自定义颜色对象。

color

const char*

使用以字串形式表示的十六進位顏色值清除螢幕(例如, “#000000”)。

hue

int

使用 0–359範圍內的整數色調值清除螢幕,表示色輪上的度數。

Return Values

此函數不傳回值。

Notes
  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
// Clear screen after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen();


// Clear screen to blue after 2 seconds
Brain.Screen.print("VEXcode");
wait(2, seconds);
Brain.Screen.clearScreen(red);

IQ(第二代)大腦螢幕的截圖,其中整個可列印區域呈現亮紅色。

setFont#

設定 IQ(第二代)大腦螢幕上顯示的文字所使用的字體。

這控制在使用螢幕文字功能(例如 print)時應用於後續文字輸出的字體。

Available Functions
void setFont(
  fontType font );

Parameters

範圍

類型

描述

font

fontType

將字體設置為以下選項之一:

  • mono12
  • mono15
  • mono20
  • mono30
  • mono40
  • mono60
  • prop20
  • prop30
  • prop40
  • prop60
這些選項如下所示。

VEX IQ Brain 螢幕截圖,顯示一系列 Mono 12 字型的數字和字母。字母 AZ 位於一行,橫跨螢幕寬度。左下角指示螢幕寬度為 26 個字符,共 9 行。
mono12

與上一張截圖相同,現在使用 Mono 15 字體。字母 AT 位於一行,橫跨螢幕寬度。左下角指示橫向 20 個字符,共 7 行。
mono15

與上一張截圖相同,但字體改為 Mono 20。字母 AP 位於一行,橫跨螢幕寬度。左下角指示橫向 16 個字符,共 5 行。
mono20

與上一張截圖相同,現在使用 Mono 30 字體。數字 1 到 9 以及一個額外的 0 位於同一行,橫跨螢幕寬度。左下角指示 3 行。
mono30

與上一張截圖相同,現在使用 Mono 40 字體。數字 1 到 8 位於第二行,橫跨螢幕寬度。
mono40

與上一張截圖相同,但字體改為 Mono 60。螢幕上顯示大號 MN 60 字體,幾乎佔據了螢幕上半部。
mono60

與上一張截圖相同,現在使用 Prop 20 字體。字母 AW 在一行中,橫跨螢幕寬度。左下角指示橫向 26 個字符,5 行。
prop20

與上一張截圖相同,現在使用 Prop 30 字體。數字 1-9 在一行中重複兩次,橫跨螢幕寬度。左下角指示橫向 18 個字符,共 3 行。
prop30

與上一張截圖相同,現在使用 Prop 40 字體。螢幕第一行顯示“Prop 40”,第二行顯示 14 個字元和 2 行。
prop40

與上一張截圖相同,現在使用 Prop 60 字體。螢幕上以大字體顯示“PROP 60”,幾乎佔據了螢幕上半部。
prop60

Return Values

此函數不傳回值。

Examples
// Display two different fonts on
// two separate lines
Brain.Screen.setFont(mono20);
Brain.Screen.print("Mono Medium");
Brain.Screen.newLine();
Brain.Screen.setFont(prop20);
Brain.Screen.print("Prop Medium");

IQ Brain 螢幕截圖,左上角有兩行白色文字。第一行是 Mono Medium,緊隨其後的第二行字體較小,是 Prop Medium。

setPenWidth#

設定繪製線條和形狀輪廓的粗細。

Available Functions
void setPenWidth(
  uint32_t width );

Parameters

範圍

類型

描述

width

uint32_t

筆的寬度,以像素為單位,範圍從 0 到 32。

Return Values

此函數不傳回值。

Notes Examples
// Draw a circle with a pen width of 5
Brain.Screen.drawCircle(40, 70, 20);
Brain.Screen.setPenWidth(5);
Brain.Screen.drawCircle(100, 70, 20);

IQ Brain 螢幕的截圖,螢幕下半部印有兩個白色圓圈。左邊的圓圈比右邊的圓圈邊框更窄。

setPenColor#

設定文字、像素、線條和形狀輪廓的顏色。

Available Functions

1 — 使用預先定義或 自訂顏色 物件設定畫筆顏色。

void setPenColor(
    const color& color );

2 — 使用十六進位顏色值設定畫筆顏色。

void setPenColor(
    const char* color );

3 — 使用色調值設定畫筆顏色。

void setPenColor(
    int hue );

Parameters

範圍

類型

描述

color

const color&

使用 color 对象设置画笔颜色。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent

color

const char*

使用以字串形式表示的十六進位顏色值來設定畫筆顏色(例如, “#FF0000”)。

hue

int

使用 0–359範圍內的整數色調值設定畫筆顏色,表示色輪上的度數(例如, 0 為紅色, 120 為綠色, 240 為藍色)。

Return Values

此函數不傳回值。

Notes
  • 項目開始時的預設畫筆顏色為 white。

  • 笔的颜色用于绘制形状的轮廓(例如使用 drawCircle 或 drawRectangle),文本和数字输出(使用 print 和 printAt),以及使用 drawPixel 绘制的单个像素。

  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
Brain.Screen.drawRectangle(100, 50, 10, 20);
Brain.Screen.setPenColor(blue);
Brain.Screen.drawRectangle(50, 50, 10, 20);

IQ Brain 螢幕的截圖,螢幕下半部畫有兩個小矩形。左邊的長方形是藍色的,右邊的長方形是白色的。

setFillColor#

設定繪製形狀時所使用的填滿顏色。

Available Functions

1 — 使用預先定義或 自訂顏色 物件設定填滿顏色。

void setFillColor(
    const color& color );

2 — 使用十六進位顏色值設定填滿顏色。

void setFillColor(
    const char* color );

3 — 使用色調值設定填滿顏色。

void setFillColor(
    int hue );

Parameters

範圍

類型

描述

color

const color&

使用 color 对象设置填充颜色。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent

color

const char*

使用以字串形式表示的十六進位顏色值設定填滿顏色(例如, “#00FF00”)。

hue

int

使用 0–359範圍內的整數色調值設定填滿顏色,表示色輪上的度數(例如, 0 為紅色, 120 為綠色, 240 為藍色)。

Return Values

此函數不傳回值。

Notes
  • 項目開始時的預設填滿顏色為 black。

  • 填滿顏色用於形狀的內部(例如使用 drawCircle 或 drawRectangle)。

  • 填滿顏色用作列印文字的背景顏色(例如使用 print 和 printAt)。

    • 如果 transparent 與印刷文本一起使用,則背景將為 black。

  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
// Draw a circle filled with yellow
Brain.Screen.setFillColor(yellow);
Brain.Screen.drawCircle(50, 50, 20);

IQ Brain 螢幕的截圖,螢幕左半部畫著一個亮黃色圓圈,圓圈邊緣有細細的白色邊框。

setOrigin#

設定大腦螢幕上用於繪圖和基於座標的列印的原點。

Available Functions
void setOrigin(
  int32_t x,
  int32_t y );

Parameters

範圍

類型

描述

x

int32_t

原點相對於大腦螢幕左上角的 x 座標,取值範圍為 0 到 159。

y

int32_t

原點相對於大腦螢幕左上角的 y 座標,取值範圍為 0 到 107。

Return Values

此函數不傳回值。

Notes
  • 預設原點位於螢幕左上角座標 (0, 0)。

  • 原點適用於座標函數,例如 drawLine、drawRectangle、drawCircle 和 printAt。

  • 此原點設定將一直有效,直到再次變更或項目重設為止。

setClipRegion#

在螢幕上定義一個矩形區域,所有圖形和文字都將限制在該區域內。該區域以外的任何內容都不會顯示。

Available Functions
void setClipRegion(
  int x,
  int y,
  int width,
  int height );

Parameters

範圍

類型

描述

x

int

剪輯區域左上角的 x 座標,取值範圍為 0 到 159 的整數。

y

int

剪輯區域左上角的 y 座標,取值範圍為 0 到 107 的整數。

width

int

裁切區域的寬度(以像素為單位),取值範圍為 0 到 159 的整數。

height

int

裁切區域的高度(以像素為單位),取值範圍為 0 到 107 的整數。

Return Values

此函數不傳回值。

Notes
  • 即使繪圖函數超出裁切區域,它們仍然會執行,但只有區域內的部分是可見的。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行更改。

  • 剪輯區域僅適用於目前執行緒。

  • 設定新的剪輯區域會取代目前執行緒之前設定的任何剪輯區域。

Examples
// Restrict text and drawings to a specific region
Brain.Screen.setClipRegion(0, 0, 120, 120);
Brain.Screen.drawRectangle(60, 60, 100, 100, red);
Brain.Screen.printAt(60, 60, "Cut off!");

IQ(第二代)大腦螢幕的截圖,白色文字顯示“Cut of”,左上角象限下方有一個實心紅色方塊,反映了剪輯區域內打印的內容。

drawPixel#

在 IQ(第二代)大腦螢幕上選定的 x 和 y 像素位置繪製一個像素。

Available Functions
void drawPixel(
  int x,
  int y );

Parameters

範圍

類型

描述

x

int

像素繪製位置的 x 座標,取值範圍為 0 到 159 之間的整數。

y

int

像素繪製位置的 y 座標,取值範圍為 0 到 107 之間的整數。

Return Values

此函數不傳回值。

Notes
  • 使用 setPenColor 設定目前畫筆顏色來繪製像素。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行設定。

  • 如果指定的像素位置在螢幕邊界之外,則不會繪製該像素。

Examples
// Draw one pixel at the center 
// of the screen
Brain.Screen.drawPixel(80, 50);

IQ Brain 螢幕的截圖,螢幕中央有一個小白點。

drawLine#

在 IQ(第二代)腦力測試畫面上,畫一條直線連接兩點。

Available Functions
void drawLine(
  int x1,
  int y1,
  int x2,
  int y2 );

Parameters

範圍

類型

描述

x1

int

直線的起始 x 座標,取值範圍為 0 到 159 的整數。

y1

int

直線的起始 y 座標,取值範圍為 0 到 107 的整數。

x2

int

直線的終點 x 座標,取值範圍為 0 到 159 的整數。

y2

int

直線的終點 y 座標,取值範圍為 0 到 107 的整數。

Return Values

此函數不傳回值。

Notes
  • 使用 setPenColor 設定目前畫筆顏色來繪製線條。

  • 線條的寬度由目前筆寬決定,該筆寬透過 setPenWidth 設定。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行設定。

  • 如果線條的任何部分超出螢幕邊界,則只繪製可見部分。

Examples
// Draw a line from the top left to 
// bottom right of the screen
Brain.Screen.drawLine(0, 0, 159, 107);

IQ Brain 螢幕截圖,從左上角到右下角畫了一條白色對角線。

drawRectangle#

在 IQ(第二代)Brain 畫面上,按指定位置和大小繪製一個矩形。

Available Functions

1 — 使用目前配置的 填滿顏色 繪製並填滿矩形。

void drawRectangle(
    int x,
    int y,
    int width,
    int height );

2 — 使用預先定義或自訂顏色物件繪製並填滿矩形。

void drawRectangle(
    int           x,
    int           y,
    int           width,
    int           height,
    const color&  color );

3 — 使用十六進位顏色值繪製並填滿矩形。

void drawRectangle(
    int           x,
    int           y,
    int           width,
    int           height,
    const char*   color );

4 — 使用色調值繪製並填滿矩形。

void drawRectangle(
    int x,
    int y,
    int width,
    int height,
    int hue );

Parameters

範圍

類型

描述

x

int

矩形左上角的 x 座標,取值範圍為 0 到 159 的整數。

y

int

矩形左上角的 y 座標,取值範圍為 0 到 107 的整數。

width

int

矩形的寬度,取值範圍為 0 到 159 的整數。

height

int

矩形的高度,取值範圍為 0 到 107 之間的整數。

color

const color&

使用 color 对象填充矩形。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
也可以使用自定义颜色对象。

color

const char*

使用十六進位顏色值填滿矩形(例如, “#FF0000”)。

hue

int

使用 0–359範圍內的色調值填滿矩形。

Return Values

此函數不傳回值。

Notes
  • 使用 setPenColor 設定目前畫筆顏色來繪製矩形輪廓。

  • 輪廓線粗細由目前筆寬決定,該筆寬透過 setPenWidth 設定。

  • 當未提供 color 參數時,矩形內部將使用 setFillColor 設定的目前填滿顏色進行填滿。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行更改。

  • 如果矩形的任何部分位於螢幕邊界之外,則只繪製可見部分。

  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
// Draw a red rectangle on the screen
Brain.Screen.drawRectangle(25, 25, 100, 50, red);

IQ Brain 螢幕的截圖,螢幕上幾乎居中處畫著一個帶有細白邊框的紅色大矩形。

drawCircle#

在 IQ(第二代)大腦畫面上,按指定位置和半徑畫一個圓。

Available Functions

1 — 使用目前配置的 填滿顏色 繪製並填入圓形。

void drawCircle(
    int x,
    int y,
    int radius );

2 — 使用預先定義或自訂顏色物件繪製並填入圓形。

void drawCircle(
    int           x,
    int           y,
    int           radius,
    const color&  color );

3 — 使用十六進位顏色值繪製並填滿一個圓。

void drawCircle(
    int           x,
    int           y,
    int           radius,
    const char*   color );

4 — 使用色相值繪製並填滿圓形。

void drawCircle(
    int x,
    int y,
    int radius,
    int hue );

Parameters

範圍

類型

描述

x

int

圓心的 x 座標,取值範圍為 0 到 159 之間的整數。

y

int

圓心的 y 座標,取值範圍為 0 到 107 的整數。

radius

int

圓的半徑,取值範圍為 0 到 107 像素的整數。

color

const color&

使用 color 对象填充圆圈。预定义颜色包括:

  • black
  • white
  • red
  • green
  • blue
  • yellow
  • orange
  • purple
  • cyan
  • transparent
也可以使用自定义颜色对象。

color

const char*

使用十六進位顏色值填滿圓圈(例如, “#FF0000”)。

hue

int

使用 0–359範圍內的色調值填滿圓形。

Return Values

此函數不傳回值。

Notes
  • 使用 setPenColor 設定目前畫筆顏色來繪製圓形的輪廓。

  • 輪廓線粗細由目前筆寬決定,該筆寬透過 setPenWidth 設定。

  • 當未提供 color 參數時,圓的內部將使用 setFillColor 設定的目前填滿顏色進行填滿。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行更改。

  • hue 參數值基於圓形色輪,如下圖所示,其中值表示色輪上的度數(例如,紅色接近 0°,綠色接近 120°,藍色接近 240°)。

一個色輪,顯示從 0 到 359 的顏色範圍,其中紅色為 0,綠色為 120,藍色為 240。

Examples
// Draw a green circle on the screen
Brain.Screen.drawCircle(80, 50, 20, green);

IQ Brain 螢幕的截圖,螢幕中央有一個帶有細白邊框的實心綠色圓圈。

drawImageFromFile#

使用儲存在 SD 卡 中的影像文件,在 IQ(第二代)Brain 螢幕上繪製影像。

Available Functions
bool drawImageFromFile(
  const char* name,
  int x,
  int y );

Parameters

範圍

類型

描述

name

const char*

SD卡上影像的檔案名稱。檔案必須具有 .bmp 或 .png 副檔名。

x

int

影像左邊緣的 x 座標(像素值,範圍從 0 到 159)。

y

int

影像頂部邊緣的繪製位置的 y 座標,以像素為單位,範圍從 0 到 107。

Return Values

傳回布林值指示影像是否成功繪製:

  • true — 影像已成功載入並繪製到螢幕上。 4
  • false — 影像無法繪製(例如,檔案不存在或無效)

Notes
  • 支援的圖像格式有: .bmp 和 .png。

  • 影像檔案大小不得超過 512 KB。

    • 建議使用 8 位元 RLE 編碼以最小化檔案大小。

  • 支援的最大影像尺寸為 Brain 螢幕尺寸(160 x 108 像素)。

  • x 和 y 座標是相對於目前螢幕原點的,可以使用 setOrigin 進行更改。

Examples
// Draw a bmp file on the Brain's screen at coordinate 0, 0
Brain.Screen.drawImageFromFile("test_image.bmp", 0, 0);

render#

啟用大腦螢幕的雙緩衝功能。呼叫後,任何繪圖功能(例如文字、形狀或圖像)在專案剩餘時間內都不會立即顯示。相反,更新內容僅在再次使用渲染 render 才會顯示。這可以實現更流暢、更可控的螢幕更新,但意味著在 render 之前,螢幕內容將不可見。

Available Functions

1 — 啟用雙緩衝或將後緩衝區渲染到螢幕。

bool render();

2 — 將後緩衝區渲染到螢幕上,並可控制垂直同步行為和可選的調度程序執行。

bool render(
    bool bVsyncWait,
    bool bRunScheduler = true );

Parameters

範圍

類型

描述

bVsyncWait

bool

  • true — Wait for the screen’s vertical refresh before rendering to reduce visual tearing.
  • false — Do not wait for the screen’s vertical refresh before rendering.

bRunScheduler

bool

可選

  • true (預設)— 允許在等待渲染時執行後台任務。 4
  • false — 不允許在等待渲染時執行後台任務。

Return Values

傳回布林值指示緩衝區中儲存的圖形是否已成功渲染到螢幕上:

  • true — 圖形已成功渲染到螢幕上。 4
  • false — 圖形無法渲染到螢幕上
  • Notes
    • 調用 render 將需要 render 用於專案的其餘部分。

    Examples
    Brain.Screen.render();
    
    // Draw text to the back buffer
    Brain.Screen.print("Render later...");
    
    // Wait for a screen press to render drawings
    while (!Brain.Screen.pressing()) {
      wait(20, msec);
    }
    Brain.Screen.render();