Προσαρμοσμένα χρώματα#

Εισαγωγή#

Το VEX IQ (2ης γενιάς) υποστηρίζει τη χρήση προσαρμοσμένων χρωμάτων για σχέδιο και κείμενο. Τα προσαρμοσμένα χρώματα μπορούν να δημιουργηθούν χρησιμοποιώντας τιμές RGB, δεκαεξαδικούς κωδικούς, τιμές HSV ή προκαθορισμένες σταθερές. Τα προσαρμοσμένα χρώματα περιλαμβάνουν μεθόδους τόσο για τη δημιουργία όσο και για την ενημέρωση χρωματικών αντικειμένων.

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

Constructors — Create a new Color object.

  • Color(value) — Accepts a predefined constant, hex string, or hex integer.

  • Color(r, g, b) — Creates a color using red, green, and blue values.

Mutators — Update an existing Color object.

  • rgb — Updates a color using new RGB values.

  • hsv — Updates a color using hue, saturation, and brightness.

  • web — Updates a color using a web hex color string.

Δημιουργία προσαρμοσμένου χρώματος#

To use a custom color, you must first create a Color object using one of the following constructors:

Hexadecimal Integer#

Δημιουργεί ένα χρώμα χρησιμοποιώντας έναν εξαψήφιο δεκαεξαδικό ακέραιο αριθμό.

Usage:
Color(value)

Παράμετρος

Περιγραφή

value

A six-digit integer in hexadecimal format (e.g., 0xFFF700 for yellow).

# Construct a yellow Color "yellow" using a
# hexadecimal value
yellow = Color(0xFFF700)

brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")

RGB#

Δημιουργεί ένα χρώμα χρησιμοποιώντας ξεχωριστές τιμές κόκκινου, πράσινου και μπλε.

Usage:
Color(r, g, b)

Παράμετρος

Περιγραφή

r

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το κόκκινο στοιχείο.

g

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το πράσινο στοιχείο.

b

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το μπλε στοιχείο.

# Construct a yellow Color "yellow" using
# RGB values
yellow = Color(255, 247, 0)

brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")

Web Color#

Δημιουργεί ένα χρώμα χρησιμοποιώντας μια συμβολοσειρά χρώματος ιστού (δεκαεξαδικός κώδικας).

Usage:
Color(value)

Παράμετρος

Περιγραφή

value

A web color as a string (hex code) (e.g., “#FFF700”).

# Construct a yellow Color "yellow" using a
# web string
yellow = Color("#FFF700")

brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")

Predefined Color#

Creates a color using a predefined Color constant.

Usage:
Color(value)

Παράμετρος

Περιγραφή

value

A built-in color constant:
BLACK, BLUE, CYAN, GREEN, ORANGE, PURPLE, RED, TRANSPARENT, WHITE, YELLOW.

# Construct a yellow Color "yellow" using a
# predefined Color constant
yellow = Color.YELLOW

brain.screen.set_pen_color(yellow)
brain.screen.print("My Yellow")

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

These methods update the color of an existing Color object. To use them, assign a Color to a variable when creating it, then call the method on that variable to change its color.

rgb#

rgb updates the color of an existing Color object using RGB values.

Usage:
variable_name.rgb(r, g, b)

Παράμετροι

Περιγραφή

r

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το κόκκινο στοιχείο του χρώματος.

g

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το πράσινο στοιχείο του χρώματος.

b

Ένας ακέραιος αριθμός από 0 έως 255 που αντιπροσωπεύει το μπλε στοιχείο του χρώματος.

# Create a custom teal color and set it as the pen color
brain_color = Color(50, 200, 180)
brain.screen.set_pen_color(brain_color)

# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)

# Draw another rectangle with a magenta outline
brain_color.rgb(170, 40, 150)
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)

hsv#

hsv updates the color of an existing Color object using HSV values.

Note: hsv can only be used to change a Color object that has already been created. It cannot be used to create a new Color Object.

Usage:
variable_name.hsv(h, s, v)

Παράμετροι

Περιγραφή

h

Ένας ακέραιος αριθμός από 0 έως 359 που αντιπροσωπεύει την απόχρωση του χρώματος.

s

Μια κινητή τιμή από 0,0 έως 1,0 που αντιπροσωπεύει τον κορεσμό του χρώματος.

v

Μια κινητή τιμή από 0,0 έως 1,0 που αντιπροσωπεύει τη φωτεινότητα του χρώματος.

# Create a custom teal color using RGB (HSV can't be used)
brain_color = Color(50, 200, 180)
brain.screen.set_pen_color(brain_color)

# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)

# Draw another rectangle with a magenta outline
brain_color.hsv(300, 0.75, 0.78)
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)

web#

web updates the color of an existing Color object using a web color (hex code).

Usage:
variable_name.web(value)

Παράμετροι

Περιγραφή

value

A web color as a string (hex code) (e.g., “#FFF700”).

# Create a custom teal color and set it as the pen color
brain_color = Color("#32C8B6")
brain.screen.set_pen_color(brain_color)

# Draw a rectangle with the teal outline
brain.screen.draw_rectangle(5, 10, 80, 40)

# Draw another rectangle with the new magenta outline
brain_color.web("#AA2896")
brain.screen.set_pen_color(brain_color)
brain.screen.draw_rectangle(5, 60, 80, 40)