screen#
print()#
The print(text, sep, precision)
method prints text on the screen using the current cursor position.
Parameters |
Description |
---|---|
text |
The text to print. |
sep |
Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is |
precision |
Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument(precision=). The default is 2. |
Returns: None.
# 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='-')
print_at()#
The print_at(text, x, y, sep, precision, opaque)
method prints text at a specific x and y coordinates on the screen.
Parameters |
Description |
---|---|
text |
The text to print. |
x |
The x position to print at as a keyword argument (x=), referenced to the screen origin. |
y |
The y position to print at as a keyword argument (y=), referenced to the screen origin. |
sep |
Optional. A string to inset between values. This must be written as a keyword argument (sep=). The default is |
precision |
Optional. The number of decimal places to display when printing simple numbers. This must be written as a keyword argument(precision=). The default is 2. |
opaque |
Optional. A boolean value indicating whether or not the text should clear background pixels. The default is |
Returns: None.
# Print the number 1 on the Brain's screen at position (100, 40).
brain.screen.print_at(1, x=100, y=40)
set_cursor()#
The set_cursor(x, y)
method sets the cursor position. The row and column spacing will take into account the selected font. The base cell size if 10x20 pixels for the MONO20
font. The top, left corner of the screen is position (x=1
, y=1
).
Parameters |
Description |
---|---|
x |
The x position of the cursor. |
y |
The y position of the cursor. |
Returns: None.
set_origin()#
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.
Parameters |
Description |
---|---|
x |
The origin’s x position relative to top left corner. |
y |
The origin’s y position relative to top left corner. |
Returns: None.
set_font()#
The set_font(fontname)
method sets the font type used for printing text on the Brain’s screen.
Parameters |
Description |
---|---|
fontname |
A valid FontType. |
Returns: None.
# Set the font type to MONO40.
brain.screen.set_font(FontType.MONO40)
set_pen_width()#
The set_pen_width(width)
method sets the pen width used for drawing lines, rectangles and circles.
Parameters |
Description |
---|---|
width |
The pen width. |
Returns: None.
# Set the pen width to 5 pixels.
brain.screen.set_pen_width(5)
set_pen_color()#
The set_pen_color(color)
method sets the pen color used for drawing lines, rectangles and circles.
Parameters |
Description |
---|---|
color |
A valid ColorType, a hex value, or a web string. |
Returns: None.
# 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")
set_fill_color()#
The set_fill_color(color)
method sets the fill color used for drawing rectangles and circles.
Parameters |
Description |
---|---|
color |
A valid ColorType, a hex value, or a web string. |
Returns: None.
# 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")
column()#
The column()
method returns the current column where text will be printed.
Returns: The current column position.
row()#
The row()
method returns the current row where text will be printed.
Returns: The current row position.
get_string_width()#
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.
Parameters |
Description |
---|---|
string |
The string to measure. |
Returns: The width of the string as an integer.
get_string_height()#
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.
This is a non-blocking method and allows the next method to run without delay.
Parameters |
Description |
---|---|
string |
The string to measure. |
Returns: The height of the string as an integer.
clear_screen()#
The clear_screen(color)
method clears the whole Brain’s screen to a single color.
This is a non-blocking method and allows the next method to run without delay.
Parameters |
Description |
---|---|
color |
Optional. A valid ColorType, a hex value, or a web string. |
Returns: None.
# 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)
clear_row()#
The clear_row(row, color)
method clears a row to a single color.
Parameters |
Description |
---|---|
row |
Optional. The row to clear. The default is the current cursor row. |
color |
Optional. A valid ColorType, a hex value, or a web string. |
Returns: None.
# 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)
next_row()#
The next_row()
method moves the cursor to the next row.
Returns: None.
draw_pixel()#
The draw_pixel(x, y)
method draws a pixel using the current pen color.
Parameters |
Description |
---|---|
x |
The x position to draw the pixel referenced to the screen origin. |
y |
The y position to draw the pixel referenced to the screen origin. |
Returns: None.
# Draw a red pixel on the Brain's screen.
brain.screen.set_pen_color(Color.RED)
brain.screen.draw_pixel(10, 10)
draw_line()#
The draw_line(x1, y1, x2, y2)
method draws a line using the current pen color.
Parameters |
Description |
---|---|
x1 |
The x position of the start of the line referenced to the screen origin. |
y1 |
The y position of the start of the line referenced to the screen origin. |
x2 |
The x position of the end of the line referenced to the screen origin. |
y2 |
The y position of the end of the line referenced to the screen origin. |
Returns: None.
# Draw a red line on the Brain's screen.
brain.screen.set_pen_color(Color.RED)
brain.screen.draw_line(10, 10, 20, 20)
draw_rectangle()#
The draw_rectangle(x, y, width, height)
method draws a rectangle on the screen using the current pen and fill colors.
Parameters |
Description |
---|---|
x |
The x position of the top-left corner of the rectangle referenced to the screen origin. |
y |
The y position of the top-left corner of the rectangle referenced to the screen origin. |
width |
The width of the rectangle. |
height |
The height of the rectangle. |
color |
Optional. A valid ColorType, a hex value, or a web string. This is the fill color of the rectangle. |
Returns: None.
# 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)
draw_circle()#
The draw_circle(x, y, radius, color)
method draws a circle using the current pen and fill colors.
Parameters |
Description |
---|---|
x |
The x position of the circle center referenced to the screen origin. |
y |
The y position of the circle center referenced to the screen origin. |
radius |
The radius of the circle. |
color |
Optional. A valid ColorType, a hex value, or a web string. This is the fill color of the circle. |
Returns: None.
# 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)
draw_image_from_file()#
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.
Parameters |
Description |
---|---|
filename |
The filename of the image. |
x |
The x coordinate for the top-left corner of the image on the screen. |
y |
The y coordinate for the top-left corner of the image on the screen. |
Returns: None.
# Draw the vex.bmp image on the Brain's screen at coordinate 0, 0.
brain.screen.draw_image_from_file('vex.bmp', 0, 0)
screen.render()#
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.
Returns: True if buffer was successfully rendered to the screen.
set_clip_region()#
The set_clip_region(x, y, width, height)
method sets the clip region for drawing the supplied rectangle.
Parameters |
Description |
---|---|
x |
The x position of the top-left corner of the rectangle, referenced to the screen origin. |
y |
The y position of the top-left corner of the rectangle, referenced to the screen origin. |
width |
The width of the rectangle. |
height |
The height of the rectangle. |
Returns: None.