屏幕#

打印()#

The print(text, sep, precision) method prints text on the screen using the current cursor position.

参数

描述

文本

要打印的文本。

九月

Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is “”.

精确

**可选。**打印简单数字时显示的小数位数。必须使用关键字参数 (precision=) 进行设置。默认值为 2。

**返回:**无。

# Print the number 1 on the Brain's screen at current
# cursor position.
brain.screen.print(1)

# Print the numbers 1, 2, 3 and 4 on the Brain's screen at
# current cursor position separated by a '-'.
brain.screen.print(1, 2, 3, 4, sep='-')

设置光标()#

The set_cursor(row, column) method sets the cursor position. The row and column spacing will take into account the selected font. The default cursor position is Row 1, Column 1.

参数

描述

设置光标的行。

柱子

设置光标的列。

**返回:**无。

设置原点()#

The set_origin(x, y) method sets the origin used for drawing graphics on the Brain’s screen. Drawing functions consider the top left corner of the Brain’s screen as the origin. This function can move the origin to an alternate position such as the center of the Brain’s screen.

参数

描述

x

原点相对于左上角的 x 位置。

y

原点相对于左上角的 y 位置。

**返回:**无。

设置字体()#

The set_font(fontname) method sets the font type used for printing text on the Brain’s screen.

参数

描述

字体名称

有效的 FontType

**返回:**无。

# Set the font type to MONO40.
brain.screen.set_font(FontType.MONO40)

设置笔宽()#

The set_pen_width(width) method sets the pen width used for drawing lines, rectangles and circles.

参数

描述

宽度

笔的宽度。

**返回:**无。

# Set the pen width to 5 pixels.
brain.screen.set_pen_width(5)

设置画笔颜色()#

The set_pen_color(color) method sets the pen color used for drawing lines, rectangles and circles.

参数

描述

颜色

有效的 ColorType、十六进制值或 Web 字符串。

**返回:**无。

# Set pen color red using a hex value.
brain.screen.set_pen_color(0xFF0000)

# Set pen color blue using predefined color.
brain.screen.set_pen_color(Color.BLUE)

# Set pen color green using web string.
brain.screen.set_pen_color("#00FF00")

设置填充颜色()#

The set_fill_color(color) method sets the fill color used for drawing rectangles and circles.

参数

描述

颜色

有效的 ColorType、十六进制值或 Web 字符串。

**返回:**无。

# Set pen color red using a hex value.
brain.screen.set_fill_color(0xFF0000)

# Set pen color blue using predefined color.
brain.screen.set_fill_color(Color.BLUE)

# Set pen color green using web string.
brain.screen.set_fill_color("#00FF00")

柱子()#

The column() method returns the current column where text will be printed.

**返回:**当前列位置。

排()#

The row() method returns the current row where text will be printed.

**返回:**当前行位置。

获取字符串宽度()#

The get_string_width(string) method gets the width of a string in pixels as if it was on the Brain’s screen. The width of a string changes based on the length of the string and the size of the font.

参数

描述

细绳

要测量的字符串。

**返回:**字符串的宽度(整数)。

获取字符串高度()#

The get_string_height(string) method gets the height of a string in pixels as if it was on the Brain’s screen. The height of a string changes based on the length of the string and the size of the font.

这是一种非等待方法,允许下一个方法无延迟运行。

参数

描述

细绳

要测量的字符串。

**返回:**字符串的高度(整数)。

清除屏幕()#

The clear_screen(color) method clears the whole Brain’s screen to a single color.

这是一种非等待方法,允许下一个方法无延迟运行。

参数

描述

颜色

**可选。**有效的 ColorType、十六进制值或 Web 字符串。

**返回:**无。

# Print VEXcode on the Brain's screen.
brain.screen.print("VEXcode")

# Clear screen to black.
brain.screen.clear_screen()

# Print VEXcode on the Brain's screen.
brain.screen.print("VEXcode")

# Clear screen to blue using predefined color.
brain.screen.clear_screen(Color.BLUE)

清除线()#

The clear_line() method clears a line of text.

**返回:**无。

清除行()#

The clear_row(row, color) method clears a row to a single color.

参数

描述

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

颜色

**可选。**有效的 ColorType、十六进制值或 Web 字符串。

**返回:**无。

# Clear Brain's screen to black.
brain.screen.clear_row()

# Clear Brain's screen to blue using predefined color.
brain.screen.clear_row(2, Color.BLUE)

换行()#

The new_line() method moves the cursor to a new line.

**返回:**无。

下一行()#

The next_row() method moves the cursor to the next row.

**返回:**无。

绘制像素()#

The draw_pixel(x, y) method draws a pixel using the current pen color.

参数

描述

x

绘制像素的 x 位置参考屏幕原点。

y

绘制像素的 y 位置参考屏幕原点。

**返回:**无。

# Draw a red pixel on the Brain's screen.
brain.screen.set_pen_color(Color.RED)
brain.screen.draw_pixel(10, 10)

绘制线()#

The draw_line(x1, y1, x2, y2) method draws a line using the current pen color.

参数

描述

x1

线的起点相对于屏幕原点的 x 位置。

y1

线的起点相对于屏幕原点的 y 位置。

x2

线尾相对于屏幕原点的 x 位置。

y2

线末端相对于屏幕原点的 y 位置。

**返回:**无。

# Draw a red line on the Brain's screen.
brain.screen.set_pen_color(Color.RED)
brain.screen.draw_line(10, 10, 20, 20)

绘制矩形()#

The draw_rectangle(x, y, width, height) method draws a rectangle on the screen using the current pen and fill colors.

参数

描述

x

矩形左上角相对于屏幕原点的 x 位置。

y

矩形左上角相对于屏幕原点的 y 位置。

宽度

矩形的宽度。

高度

矩形的高度。

颜色

可选。 有效的 ColorType、十六进制值或 Web 字符串。这是矩形的填充颜色。

**返回:**无。

# Draw a green rectangle on the screen that is filled using blue.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.set_fill_color(Color.BLUE)
brain.screen.draw_rectangle(10, 10, 20, 20)

# Draw a green rectangle on the screen that is filled using red.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.draw_rectangle(50, 50, 20, 20, Color.RED)

画圆()#

The draw_circle(x, y, radius, color) method draws a circle using the current pen and fill colors.

参数

描述

x

圆心相对于屏幕原点的 x 位置。

y

圆心相对于屏幕原点的 y 位置。

半径

圆的半径。

颜色

可选。 有效的 ColorType、十六进制值或 Web 字符串。这是圆圈的填充颜色。

**返回:**无。

# Draw a green circle on the Brain's screen that is filled using blue.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.set_fill_color(Color.BLUE)
brain.screen.draw_circle(50, 50, 10)

# Draw a green circle on the Brain's screen that is filled using red.
brain.screen.set_pen_color(Color.GREEN)
brain.screen.draw_circle(100, 50, 10, Color.RED)

从文件绘制图像()#

The draw_image_from_file(filename, x, y) method draws an image from the SD card. The filename you put when calling the method must be located on the SD card.

参数

描述

文件名

图像的文件名。

x

屏幕上图像左上角的 x 坐标。

y

屏幕上图像左上角的 y 坐标。

**返回:**无。

# Draw the vex.bmp image on the Brain's screen at coordinate 0, 0.
brain.screen.draw_image_from_file('vex.bmp', 0, 0)

屏幕.渲染()#

The render() method switches drawing to double buffered and renders the Brain’s screen. Once called, further drawing will not appear on the Brain’s screen until the next time render is called.

**返回:**如果缓冲区成功呈现到屏幕,则返回 True。

设置剪辑区域()#

The set_clip_region(x, y, width, height) method sets the clip region for drawing the supplied rectangle.

参数

描述

x

矩形左上角的 x 位置(参考屏幕原点)。

y

矩形左上角的 y 位置(参考屏幕原点)。

宽度

矩形的宽度。

高度

矩形的高度。

**返回:**无。