Οθόνη#

Εισαγωγή#

Οι μέθοδοι οθόνης ελέγχουν τον τρόπο με τον οποίο ο εγκέφαλος IQ (2ης γενιάς) εμφανίζει κείμενο, αριθμούς και γραφικά στην ενσωματωμένη οθόνη του.

Για το σχέδιο, η ανάλυση του Brain είναι 160 x 108 pixel.

This page uses brain as the example Brain name. Replace it with your own configured name as needed.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Εκτύπωση δρομέα — Τοποθέτηση και εκτύπωση κειμένου.

  • print — Prints text, numbers, or variable values at the current cursor position.

  • set_cursor — Moves the cursor to a specific row and column.

  • next_row — Moves the cursor to column 1 of the next row.

  • clear_row — Clears a row of text.

  • row — Returns the row where text will be printed.

  • column — Returns the column where text will be printed.

  • print_at — Prints text, numbers, or variable values at a specific x and y coordinate.

  • get_string_width — Returns the width of a string in pixels using the current font.

  • get_string_height — Returns the height of a string in pixels using the current font.

Μεταλλαγμένοι — Αλλάξτε τις ρυθμίσεις της οθόνης, τα χρώματα και τη συμπεριφορά σχεδίασης.

  • clear_screen — Clears the screen of all drawings and text.

  • set_font — Sets the font for printed text.

  • set_pen_width — Sets the thickness of drawn lines and shape outlines.

  • set_pen_color — Sets the color of text, pixels, lines, and shape outlines.

  • set_fill_color — Sets the fill color for drawn shapes and printed text backgrounds.

  • set_origin — Sets the origin used for coordinate-based printing and drawing.

Σχεδίαση — Προσθήκη γραφικών στην οθόνη.

Εκτύπωση δρομέα#

print#

print prints text, numbers, or variable values on the Brain screen at the current cursor position and font.

Usage:
brain.screen.print(text, precision, opaque)

Παράμετροι

Περιγραφή

text

Το κείμενο, ο αριθμός ή η τιμή μεταβλητής που θα εκτυπωθεί στην οθόνη.

precision

Optional. The number of decimal places to display when displaying numbers. This must be written as a keyword argument, ie:precision=3. Default is 2.

opaque

Optional. opaque=True — The background of the text will be filled with the current fill color or black by default. opaque=False (default) — The background of the text will match the screen’s background color.

# Display a message at the starting
# cursor position
brain.screen.print("Hello, Robot!")

Ένα στιγμιότυπο οθόνης της οθόνης VEX IQ Brain αναφέρει την ένδειξη "Γεια σου, Ρομπότ!" με λευκό κείμενο στην πρώτη γραμμή.

# 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 moves the cursor to a specific row and column on the Brain screen. The next print call will start printing at that location. How many rows and columns can comfortably fit depends on the selected font.

Monospaced fonts have characters that are all the same width, making text placement consistent. In contrast, proportional fonts vary in character width, so some letters take up more space than others. However, regardless of which type is used, set_cursor positions the cursor based on row and column size, not font style. The font size can be adjusted using set_font.

Usage:
brain.screen.set_cursor(row, column)

Παράμετροι

Περιγραφή

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)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain αναφέρει 23,19 με λευκό κείμενο στην επάνω αριστερή γωνία.

next_row#

next_row moves the cursor to column 1 on the next row on the Brain screen.

Usage:
brain.screen.next_row()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display two lines of text
brain.screen.print("Line 1")
brain.screen.next_row()
brain.screen.print("Line 2")

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain αναφέρει τη Γραμμή 1 με λευκό κείμενο στην επάνω αριστερή γωνία και τη Γραμμή 2 ακριβώς από κάτω.

clear_row#

clear_row clears a single row of text on the Brain screen.

Usage:
brain.screen.clear_row(row, color)

Παράμετροι

Περιγραφή

σειρά

Προαιρετικό. Η γραμμή που θα διαγραφεί. Η προεπιλογή είναι η τρέχουσα γραμμή του δρομέα.

χρώμα

Optional. The color to apply to the cleared row. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# 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 returns the row where text will be printed as an integer.

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με έναν λευκό αριθμό 3 τυπωμένο στην αριστερή άκρη της οθόνης, κεντραρισμένο κάθετα, στη θέση της στήλης 2 της σειράς 3.

column#

column returns the column where text will be printed as an integer.

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με έναν λευκό αριθμό 2 τυπωμένο στην αριστερή άκρη της οθόνης, κεντραρισμένο κάθετα, στη θέση 2 της στήλης 3 της σειράς 3.

get_string_width#

get_string_width returns the width of a string in pixels as an integer, as it would appear on the Brain’s screen. The width varies depending on the string’s length and the current font.

Usage:
brain.screen.get_string_width(string)

Παράμετροι

Περιγραφή

string

Η χορδή που θα μετρηθεί.

get_string_height#

get_string_height returns the height of a string in pixels as an integer, as it would appear on the Brain screen. The height varies depending on the string’s length and the current font.

Usage:
brain.screen.get_string_height(string)

Παράμετροι

Περιγραφή

string

Η χορδή που θα μετρηθεί.

Μεταλλάκτες#

clear_screen#

clear_screen clears all drawings and text from the Brain’s screen.

Usage:
brain.screen.clear_screen(color)

Παράμετροι

Περιγραφή

color

Optional. Sets the screen color. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με ολόκληρη την εκτυπώσιμη περιοχή σε έντονο κόκκινο χρώμα.

set_font#

set_font sets the font used for displaying text on the Brain screen. This font will apply to all text printed with print or print_at. The default font at the start of a project is MONO20.

Usage:
brain.screen.set_font(fontname)

Παράμετρος

Περιγραφή

fontname

Sets the font to one of the following:

  • MONO12
  • MONO15
  • MONO20
  • MONO30
  • MONO40
  • MONO60
  • PROP20
  • PROP30
  • PROP40
  • PROP60
These options are shown below.

Στιγμιότυπο οθόνης της οθόνης 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

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με λευκό κείμενο σε δύο γραμμές στην επάνω αριστερή γωνία. Η πρώτη γραμμή γράφει Mono Medium και η δεύτερη γραμμή ακριβώς από κάτω γράφει Prop Medium σε μικρότερη γραμματοσειρά.

set_pen_width#

set_pen_width sets the thickness of drawn lines and shape outlines.

Usage:
brain.screen.set_pen_width(width)

Παράμετρος

Περιγραφή

width

Το πλάτος της πένας, σε pixel, κυμαίνεται από 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)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με δύο λευκούς κύκλους τυπωμένους στο κάτω μισό της οθόνης. Ο κύκλος στα αριστερά έχει στενότερο περίγραμμα από αυτόν στα δεξιά.

set_pen_color#

set_pen_color sets the color of text, pixels, lines, and shape outlines.

Usage:
brain.screen.set_pen_color(color)

Παράμετρος

Περιγραφή

color

Optional. The pen and font color to use. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με δύο μικρά ορθογώνια σχεδιασμένα στο κάτω μισό της οθόνης. Το ορθογώνιο στα αριστερά είναι μπλε και αυτό στα δεξιά είναι λευκό.

set_fill_color#

set_fill_color sets the fill color used when shapes are drawn.

Usage:
brain.screen.set_fill_color(color)

Παράμετρος

Περιγραφή

color

Optional. The fill color to use. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a yellow circle
brain.screen.set_fill_color(Color.YELLOW)
brain.screen.draw_circle(50, 50, 20)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με έναν φωτεινό κίτρινο κύκλο με ένα λεπτό λευκό περίγραμμα σχεδιασμένο στο αριστερό μισό της οθόνης.

set_origin#

set_origin sets the origin used for drawing and coordinate-based printing on the Brain screen. By default, the origin is the top-left corner of the screen.

Usage:
brain.screen.set_origin(x, y)

Παράμετρος

Περιγραφή

x

Η νέα συντεταγμένη x που θα οριστεί ως αρχή, δίνεται ως ακέραιος αριθμός από 0 έως 159.

y

Η νέα συντεταγμένη 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)

Ένα στιγμιότυπο οθόνης μιας οθόνης IQ Brain με μια γραμμή while που ξεκινά ελαφρώς αριστερά από το κέντρο και εκτείνεται διαγώνια προς τα κάτω προς τα δεξιά προς την κάτω δεξιά γωνία της οθόνης.

Ισοπαλία#

draw_pixel#

draw_pixel draws one pixel at the selected x and y coordinate using the current pen color.

Usage:
brain.screen.draw_pixel(x, y)

Παράμετρος

Περιγραφή

x

Η συντεταγμένη x όπου θα σχεδιαστεί το εικονοστοιχείο, η οποία δίνεται ως ακέραιος αριθμός από 0 έως 159.

y

Η συντεταγμένη y όπου θα σχεδιαστεί το εικονοστοιχείο, η οποία δίνεται ως ακέραιος αριθμός από 0 έως 107.

# Draw one pixel at the center
# of the screen
brain.screen.draw_pixel(80, 50)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με μια μικροσκοπική λευκή κουκκίδα στο κέντρο της οθόνης.

draw_line#

draw_line draws a line from the first screen coordinate (x1, y1) to the second screen coordinate (x2, y2) using the current pen width and pen color.

The x and y-coordinates use the default origin of (0, 0) unless a different origin has been set using set_origin.

Usage:
brain.screen.draw_line(x1, y1, x2, y2)

Παράμετρος

Περιγραφή

x1

Η αρχική συντεταγμένη x της γραμμής, που δίνεται ως ακέραιος αριθμός από 0 έως 159.

y1

Η αρχική συντεταγμένη y της γραμμής, που δίνεται ως ακέραιος αριθμός από 0 έως 107.

x2

Η τελική συντεταγμένη x της γραμμής, που δίνεται ως ακέραιος αριθμός από 0 έως 159.

y2

Η τελική συντεταγμένη y της γραμμής, η οποία δίνεται ως ακέραιος αριθμός από 0 έως 107.

# Draw a line from the top left to
# bottom right of the screen
brain.screen.draw_line(0, 0, 159, 107)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με μια λευκή διαγώνια γραμμή από την επάνω αριστερή γωνία προς την κάτω δεξιά γωνία.

draw_rectangle#

draw_rectangle draws a rectangle with its top-left corner at the selected (x, y) coordinate and a size determined by the given width and height, all measured in pixels. The rectangle’s outline is drawn using the current pen width and pen color. The interior is filled with the current fill color, unless the optional color parameter is used.

The x and y-coordinates use the default origin of (0,0) unless a different origin has been set using set_origin.

Usage:
brain.screen.draw_rectangle(x, y, width, height, color)

Παράμετρος

Περιγραφή

x

Η συντεταγμένη x της επάνω αριστερής γωνίας του ορθογωνίου, που δίνεται ως ακέραιος αριθμός από 0 έως 159.

y

Η συντεταγμένη y της επάνω αριστερής γωνίας του ορθογωνίου, που δίνεται ως ακέραιος αριθμός από 0 έως 107.

width

Το πλάτος του ορθογωνίου, σε pixel.

height

Το ύψος του ορθογωνίου, σε pixel.

color

Optional. The fill color of the rectangle. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a red rectangle on the screen
brain.screen.draw_rectangle(25, 25, 100, 50, Color.RED)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με ένα μεγάλο κόκκινο ορθογώνιο με ένα λεπτό λευκό περίγραμμα σχεδόν στο κέντρο της οθόνης.

draw_circle#

draw_circle draws a circle with its center at the selected (x, y) coordinate and a size determined by the given radius, all measured in pixels. The circle’s outline is drawn using the current pen width and pen color. The interior is filled with the current fill color, unless the optional color parameter is used.

The x and y-coordinates use the default origin of (0,0) unless a different origin has been set using set_origin.

Usage:
brain.screen.draw_circle(x, y, radius, color)

Παράμετρος

Περιγραφή

x

Η συντεταγμένη x του κέντρου του κύκλου, που δίνεται ως ακέραιος αριθμός από 0 έως 159.

y

Η συντεταγμένη y του κέντρου του κύκλου, που δίνεται ως ακέραιος αριθμός από 0 έως 107.

radius

Η ακτίνα του κύκλου, σε pixel.

color

Optional. The fill color of the circle. Options include:

  • Color.BLACK
  • Color.BLUE
  • Color.BLUE_GREEN
  • Color.BLUE_VIOLET
  • Color.GREEN
  • Color.ORANGE
  • Color.PURPLE
  • Color.RED
  • COLOR.RED_ORANGE
  • Color.RED_VIOLET
  • Color.VIOLET
  • Color.WHITE
  • Color.YELLOW
  • Color.YELLOW_GREEN
  • Color.YELLOW_ORANGE
You can also specify a custom color.

# Draw a green circle on the screen
brain.screen.draw_circle(80, 50, 20, Color.GREEN)

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με έναν συμπαγή πράσινο κύκλο με ένα λεπτό λευκό περίγραμμα στο κέντρο της οθόνης.

set_clip_region#

set_clip_region defines a rectangular area on the screen where all drawings and text will be confined. Any content outside this region will not be displayed.

Usage:
brain.screen.set_clip_region(x, y, width, height)

Παράμετρος

Περιγραφή

x

Η συντεταγμένη x της επάνω αριστερής γωνίας της περιοχής αποκοπής, που δίνεται ως ακέραιος αριθμός ή κινητή υποδιαστολή από 0 έως 159.

y

Η συντεταγμένη y της επάνω αριστερής γωνίας της περιοχής αποκοπής, που δίνεται ως ακέραιος αριθμός ή κινητή υποδιαστολή από 0 έως 107.

width

Το πλάτος της περιοχής κλιπ σε pixel.

height

Το ύψος της περιοχής κλιπ σε pixel.

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

Ένα στιγμιότυπο οθόνης της οθόνης IQ Brain με λευκό κείμενο κοντά στο κέντρο της οθόνης που γράφει Αποκοπή από, με ένα συμπαγές κόκκινο τετράγωνο ακριβώς από κάτω, που δείχνει τι εκτυπώνεται στην περιοχή του αποσπάσματος.

render#

render enables double buffering for the Brain’s screen. Once called, any drawing commands (like text, shapes, or images) will no longer appear immediately for the rest of the project. Instead, updates will only be shown when render is used again. This allows for smoother and more controlled screen updates, but means nothing will be visible until render is used.

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