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

Εισαγωγή#

The color class is used to define and modify colors for drawing shapes and displaying text on the IQ (2nd gen) Brain Screen. Colors can be created using RGB values, hexadecimal color codes, or predefined color constants.

Κατασκευαστές κλάσεων#

1 Creates a color object with no assigned color.

color();

2 Creates a color object from a hexadecimal or integer value.

color( 
  int value );

3 Creates a color object from RGB values.

color( 
  uint8_t r, 
  uint8_t g, 
  uint8_t b );

Καταστροφέας κλάσης#

Destroys the color object and releases associated resources.

~color();

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

value

int

The color value, which can be either a hexadecimal RGB integer (for example, 0xFFF700) or one of the predefined color constants listed below.

r

uint8_t

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

g

uint8_t

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

b

uint8_t

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

Σημειώσεις#

  • The following predefined color constants are supported:

    • black
    • blue
    • blue_green
    • blue_violet
    • cyan
    • green
    • orange
    • purple
    • red
    • red_orange
    • red_violet
    • transparent
    • violet
    • white
    • yellow
    • yellow_green
    • yellow_orange

Παράδειγμα#

// Create the color yellow using a hexadecimal value
color myYellow = color(0xFFF700);

// Create a color using RGB values
color myBlue = color(0, 100, 255);

// Create a color using a predefined constant
color myRed = color(red);

Συναρτήσεις Μελών#

The color class includes the following member functions:

  • rgb — Updates the color using RGB values.

  • hsv — Updates the color using HSV values.

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

Before calling any color member functions, a color instance must be created, as shown below:

// Create a color using RGB values
color brainColor = color(255, 128, 0);

rgb#

Updates the color of an existing color object using RGB values.

Available Functions

1 Ενημερώνει ένα χρωματικό αντικείμενο με μια τιμή RGB σε πακέτο.

uint32_t rgb( 
  uint32_t value );

2 Ενημερώνει ένα χρωματικό αντικείμενο με ξεχωριστές τιμές RGB.

uint32_t rgb( 
  uint8_t r, 
  uint8_t g, 
  uint8_t b );

Parameters

Παράμετρος

Τύπος

Περιγραφή

value

uint32_t

Μια συσκευασμένη τιμή RGB που περιέχει και τα τρία στοιχεία χρώματος.

r

uint8_t

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

g

uint8_t

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

b

uint8_t

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

Return Values

Returns a uint32_t representing the packed RGB value of the updated color.

Examples
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);

// Change the color to magenta for a second rectangle
brainColor.rgb(170, 40, 150);

Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);

// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);

// Change the color to magenta for a second rectangle
brainColor.rgb(0xAA2896);

Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);

hsv#

Updates the color of an existing color object using hue, saturation, and brightness values.

Available Functions
color& hsv( 
  uint32_t hue, 
  double   sat, 
  double   value );

Parameters

Παράμετρος

Τύπος

Περιγραφή

hue

uint32_t

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

sat

double

Ένα διπλάσιο από 0,0 έως 1,0 που αντιπροσωπεύει τον κορεσμό του χρώματος.

value

double

Ένα διπλάσιο από 0,0 έως 1,0 που αντιπροσωπεύει τη φωτεινότητα του χρώματος.

Return Values

Returns a reference to the updated color object.

Examples
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);

// Change the color to magenta for a second rectangle
brainColor.hsv(300, 0.75, 0.78);

Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);

web#

Updates the color of an existing color object using a hexadecimal or web color value.

Available Functions
color& web( 
  const char* color );

Parameters

Παράμετρος

Τύπος

Περιγραφή

color

const char*

A hexadecimal or web color value that defines a specific color (e.g., “#FF0000” for red).

Return Values

Returns a reference to the updated color object.

Examples
// Draw a rectangle with a custom teal color
color brainColor = color(50, 200, 180);
Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 0, 480, 120);

// Change the color to magenta for a second rectangle
brainColor.web("#AA2896");

Brain.Screen.setFillColor(brainColor);
Brain.Screen.drawRectangle(0, 120, 480, 120);