画面#
導入#
スクリーン方式は、IQ(第2世代)Brainが内蔵スクリーンにテキスト、数字、グラフィックを表示する方法を制御します。
描画時のBrainの解像度は160×108ピクセルです。
このページでは、例として Brain brain を使用しています。必要に応じて、ご自身で設定した名前に置き換えてください。
以下にすべてのメソッドの一覧を示します。
カーソル印刷 — テキストを配置して印刷します。
print— 現在のカーソル位置にテキスト、数値、または変数値を出力します。set_cursor— カーソルを特定の行と列に移動します。next_row— カーソルを次の行の 1 列目に移動します。clear_row— テキストの行をクリアします。row— テキストが印刷される行を返します。column— テキストが印刷される列を返します。print_at— 特定の x 座標と y 座標にテキスト、数値、または変数値を出力します。get_string_width— 現在のフォントを使用して、文字列の幅をピクセル単位で返します。get_string_height— 現在のフォントを使用して文字列の高さをピクセル単位で返します。
ミューテーター — 画面設定、色、描画動作を変更します。
clear_screen— 画面上のすべての描画とテキストを消去します。set_font— 印刷テキストのフォントを設定します。set_pen_width— 描画された線と図形の輪郭の太さを設定します。set_pen_color— テキスト、ピクセル、線、図形の輪郭の色を設定します。set_fill_color— 描画された図形と印刷されたテキストの背景の塗りつぶしの色を設定します。set_origin— 座標ベースの印刷と描画に使用される原点を設定します。
描画 — 画面にグラフィックを追加します。
draw_pixel— 座標に 1 つのピクセルを描画します。draw_line— 2点間に線を描画します。draw_rectangle— 長方形を描画します。draw_circle— 円を描画します。set_clip_region— 描画とテキストが表示される場所を制限します。render— 呼び出された時のみ、テキストと描画でブレインの画面を更新します。
カーソル印字#
print#
print は、現在の カーソル位置 と フォント にテキスト、数値、または変数値を Brain 画面に表示します。
Usage:
brain.screen.print(text, precision, opaque)
パラメータ |
説明 |
|---|---|
|
画面に表示するテキスト、数値、または変数値。 |
|
オプション。数値を表示する際に表示する小数点以下の桁数を指定します。これはキーワード引数として記述する必要があります(例: |
|
オプション |
# Display a message at the starting
# cursor position
brain.screen.print("Hello, Robot!")

# Display a percentage with 4 decimal
# places and a blue background
brain.screen.set_fill_color(Color.BLUE)
brain.screen.print((42/100), precision = 4, opaque = True)
set_cursor#
set_cursor は、カーソルを Brain 画面上の特定の行と列に移動します。次の print 呼び出しは、その位置から印刷を開始します。快適に収まる行と列の数は、選択されたフォントによって異なります。
等幅フォントは文字の幅がすべて同じなので、テキストの配置が一定になります。一方、プロポーショナルフォントは文字の幅が異なるため、文字によって占めるスペースが異なります。ただし、どちらのタイプを使用する場合でも、 set_cursor フォントスタイルではなく、行と列のサイズに基づいてカーソルを配置します。フォントサイズは set_font を使用して調整できます。
Usage:
brain.screen.set_cursor(row, column)
パラメータ |
説明 |
|---|---|
|
カーソルを移動する行。 |
|
カーソルを移動させる列。 |
# Repeatedly print the Brain's timer at
# the top left of the screen
while True:
brain.screen.print(brain.timer.time(SECONDS))
brain.screen.next_row()
wait(1, SECONDS)
brain.screen.clear_screen()
brain.screen.set_cursor(1, 1)

next_row#
next_row 、ブレイン画面の次の行の 1 列目にカーソルを移動します。
Usage:
brain.screen.next_row()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Display two lines of text
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

clear_row#
clear_row は、Brain 画面上のテキストの 1 行を消去します。
Usage:
brain.screen.clear_row(row, color)
パラメータ |
説明 |
|---|---|
行 |
オプション。クリアする行を指定します。デフォルトは現在のカーソル行です。 |
色 |
Optional. The color to apply to the cleared row. Options include:
|
# Display text on two rows
brain.screen.print("This text stays")
brain.screen.next_row()
brain.screen.print("This disappears")
# Wait 3 seconds before clearing
# only the second row
wait(3, SECONDS)
brain.screen.clear_row()
# Turn the 5th row green
brain.screen.clear_row(5, Color.GREEN)
row#
row は、テキストが整数として印刷される行を返します。
Usage:
brain.screen.row()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Set cursor to (3,2) and print
# row number
brain.screen.set_cursor(3, 2)
brain.screen.print(brain.screen.row())

column#
column は、テキストが整数として出力される列を返します。
Usage:
brain.screen.column()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Set cursor to (3,2) and print
# column number
brain.screen.set_cursor(3, 2)
brain.screen.print(brain.screen.column())

print_at#
print_at は、現在設定されている font および origin を使用して、指定された x 座標と y 座標 (ピクセル単位) にテキスト、数値、または変数値を Brain 画面に表示します。このメソッドは、現在のカーソル位置を無視します。
Usage:
brain.screen.print_at(text, x, y, precision, opaque)
パラメータ |
説明 |
|---|---|
|
印刷するテキスト、数値、または変数値。 |
|
キーワード引数として出力するx座標。例: |
|
キーワード引数として出力するy座標。例: |
|
オプション。数値を表示する際に表示する小数点以下の桁数を指定します。これはキーワード引数として記述する必要があります(例: |
|
オプション |
# Print the number 1 on the Brain's screen at position (100, 40)
brain.screen.print_at(1, x=100, y=40)

# Display 1/3 with 3 decimal places and a blue background
brain.screen.set_fill_color(Color.BLUE)
brain.screen.print_at((1/3), x=100, y=40, precision=3, opaque=True)
get_string_width#
get_string_width は、Brain の画面に表示される文字列の幅をピクセル単位で整数として返します。幅は、文字列の長さと 現在のフォント によって異なります。
Usage:
brain.screen.get_string_width(string)
パラメータ |
説明 |
|---|---|
|
測定用の紐。 |
get_string_height#
get_string_height 、Brain 画面に表示される文字列の高さをピクセル単位で整数として返します。高さは、文字列の長さと 現在のフォント によって異なります。
Usage:
brain.screen.get_string_height(string)
パラメータ |
説明 |
|---|---|
|
測定用の紐。 |
変異誘発者#
clear_screen#
clear_screen は、Brain の画面からすべての描画とテキストを消去します。
Usage:
brain.screen.clear_screen(color)
パラメータ |
説明 |
|---|---|
|
Optional. Sets the screen color. Options include:
|
# Draw a circle and clear it after
# 2 seconds
brain.screen.draw_circle(80, 50, 20)
wait(2, SECONDS)
brain.screen.clear_screen()
# Turn the screen red
brain.screen.clear_screen(Color.RED)

set_font#
set_font は Brain 画面にテキストを表示するのに使用するフォントを設定します。このフォントは print または print_at で印刷されるすべてのテキストに適用されます。プロジェクト開始時のデフォルトフォントは MONO20です。
Usage:
brain.screen.set_font(fontname)
パラメータ |
説明 |
|---|---|
|
フォントを以下のいずれかに設定します:
|
|
|
|
|---|---|---|
|
|
|
|
|
|
|
# Display two different fonts on
# two separate lines
brain.screen.set_font(FontType.MONO20)
brain.screen.print("Mono Medium")
brain.screen.next_row()
brain.screen.set_font(FontType.PROP20)
brain.screen.print("Prop Medium")

set_pen_width#
set_pen_width は、描画される線と図形の輪郭の太さを設定します。
Usage:
brain.screen.set_pen_width(width)
パラメータ |
説明 |
|---|---|
|
ペンの幅(ピクセル単位)。0~32の範囲で指定します。 |
# Draw two circles with
# different pen widths
brain.screen.draw_circle(40, 70, 20)
brain.screen.set_pen_width(5)
brain.screen.draw_circle(100, 70, 20)

set_pen_color#
set_pen_color は、テキスト、ピクセル、線、および図形の輪郭の色を設定します。
Usage:
brain.screen.set_pen_color(color)
パラメータ |
説明 |
|---|---|
|
Optional. The pen and font color to use. Options include:
|
# Draw two rectangles with
# different colors
brain.screen.draw_rectangle(100, 50, 10, 20)
brain.screen.set_pen_color(Color.BLUE)
brain.screen.draw_rectangle(50, 50, 10, 20)

set_fill_color#
set_fill_color は、図形を描画する際に使用される塗りつぶしの色を設定します。
Usage:
brain.screen.set_fill_color(color)
パラメータ |
説明 |
|---|---|
|
Optional. The fill color to use. Options include:
|
# Draw a yellow circle
brain.screen.set_fill_color(Color.YELLOW)
brain.screen.draw_circle(50, 50, 20)

set_origin#
set_origin は、Brain画面上での描画および座標ベースの印刷に使用される原点を設定します。デフォルトでは、原点は画面の左上隅です。
Usage:
brain.screen.set_origin(x, y)
パラメータ |
説明 |
|---|---|
|
原点として設定する新しいx座標。0から159までの整数で指定します。 |
|
原点として設定する新しいy座標。0から107までの整数で指定します。 |
# Draw a line with the origin set to (50, 50)
brain.screen.set_origin(50, 50)
brain.screen.draw_line(1, 1, 159, 107)

描く#
draw_pixel#
draw_pixel 、現在の ペンカラー を使用して、選択された x 座標と y 座標に 1 つのピクセルを描画します。
Usage:
brain.screen.draw_pixel(x, y)
パラメータ |
説明 |
|---|---|
|
ピクセルが描画されるx座標。0から159までの整数で指定します。 |
|
ピクセルが描画されるy座標。0から107までの整数で指定します。 |
# Draw one pixel at the center
# of the screen
brain.screen.draw_pixel(80, 50)
![]()
draw_line#
draw_line は、現在の ペン幅 と ペン色 を使用して、最初の画面座標 (x1, y1) から 2 番目の画面座標 (x2, y2) 線を描画します。
x座標とy座標は、set_originを使用して別の原点が設定されていない限り、デフォルトの原点(0, 0)を使用します。
Usage:
brain.screen.draw_line(x1, y1, x2, y2)
パラメータ |
説明 |
|---|---|
|
直線の開始位置を示すx座標。0から159までの整数で指定します。 |
|
直線の開始y座標。0から107までの整数で指定します。 |
|
直線の終点のx座標。0から159までの整数で表されます。 |
|
直線の終点のy座標。0から107までの整数で表されます。 |
# Draw a line from the top left to
# bottom right of the screen
brain.screen.draw_line(0, 0, 159, 107)

draw_rectangle#
draw_rectangle 、左上隅が選択された (x, y) 座標にあり、指定された幅と高さでサイズが決まる長方形を描画します。サイズはすべてピクセル単位で測定されます。長方形の輪郭は、現在の ペン幅 と ペン色 を使用して描画されます。オプションの color パラメータが使用されない限り、内部は現在の 塗りつぶし色 で塗りつぶされます。
x座標とy座標は、set_originを使用して別の原点が設定されていない限り、デフォルトの原点(0,0)を使用します。
Usage:
brain.screen.draw_rectangle(x, y, width, height, color)
パラメータ |
説明 |
|---|---|
|
長方形の左上隅のx座標。0から159までの整数で表されます。 |
|
長方形の左上隅のy座標。0から107までの整数で表されます。 |
|
長方形の幅(ピクセル単位)。 |
|
長方形の高さ(ピクセル単位)。 |
|
Optional. The fill color of the rectangle. Options include:
|
# Draw a red rectangle on the screen
brain.screen.draw_rectangle(25, 25, 100, 50, Color.RED)

draw_circle#
draw_circle は、選択された (x, y) 座標を中心とし、指定された半径でサイズが決定される円を描画します。サイズはすべてピクセル単位で測定されます。円の輪郭は、現在の ペン幅 と ペン色 を使用して描画されます。オプションの color パラメータが使用されない限り、内部は現在の 塗りつぶし色 で塗りつぶされます。
x座標とy座標は、set_originを使用して別の原点が設定されていない限り、デフォルトの原点(0,0)を使用します。
Usage:
brain.screen.draw_circle(x, y, radius, color)
パラメータ |
説明 |
|---|---|
|
円の中心のx座標。0から159までの整数で表されます。 |
|
円の中心のy座標。0から107までの整数で表されます。 |
|
円の半径(ピクセル単位)。 |
|
Optional. The fill color of the circle. Options include:
|
# Draw a green circle on the screen
brain.screen.draw_circle(80, 50, 20, Color.GREEN)

set_clip_region#
set_clip_region 画面上の矩形領域を定義し、そこにすべての描画とテキストが収まるようにします。この領域外のコンテンツは表示されません。
Usage:
brain.screen.set_clip_region(x, y, width, height)
パラメータ |
説明 |
|---|---|
|
クリップ領域の左上隅のx座標。整数または0から159までの浮動小数点数で指定します。 |
|
クリップ領域の左上隅のy座標。整数または0から107までの浮動小数点数で指定します。 |
|
クリップ領域の幅(ピクセル単位)。 |
|
クリップ領域の高さ(ピクセル単位)。 |
# Restrict text and drawings to a specific region
brain.screen.set_clip_region(0, 0, 120, 120)
brain.screen.draw_rectangle(60, 60, 100, 100, Color.RED)
brain.screen.print_at("Cut off!", x=60, y=60)

render#
render は、Brain の画面でダブルバッファリングを有効にします。一度呼び出されると、テキスト、図形、画像などの描画コマンドは、プロジェクトの残りの部分ではすぐに表示されなくなります。代わりに、更新は render 再度使用されたときにのみ表示されます。これにより、画面の更新がよりスムーズかつ制御しやすくなりますが、 render 使用されるまで何も表示されません。
Usage:
brain.screen.render()
パラメータ |
説明 |
|---|---|
このメソッドにはパラメータがありません。 |
# Render text after moving
brain.screen.render()
brain.screen.print("Render later...")
drivetrain.drive_for(FORWARD, 100, MM)
drivetrain.turn_for(RIGHT, 90, DEGREES)
brain.screen.render()









