Özel Renkler#

giriiş#

color sınıfı, IQ (1. nesil) Beyni ile renkleri tanımlamak ve değiştirmek için kullanılır. Renkler, RGB değerleri, onaltılık renk kodları, HSV değerleri veya önceden tanımlanmış renk sabitleri kullanılarak oluşturulabilir.

Sınıf Oluşturucuları#

1 — Atanmamış renge sahip color nesnesi oluşturur.

color();

2 — Onaltılık veya tam sayı değerinden color nesnesi oluşturur.

color( 
  int value );

3 — RGB değerlerinden color nesnesi oluşturur.

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

Sınıf Yıkıcısı#

color nesneyi yok eder ve ilgili kaynakları serbest bırakır.

~color();

Parametreler#

Parametre

Tip

Tanım

value

int

Renk değeri, onaltılık RGB tamsayı (örneğin, 0xFFF700) veya aşağıda listelenen önceden tanımlanmış renk sabitlerinden biri olabilir.

r

uint8_t

Kırmızı bileşeni temsil eden 0 ile 255 arasında bir tamsayı.

g

uint8_t

Yeşil bileşeni temsil eden 0 ile 255 arasında bir tamsayı.

b

uint8_t

Mavi bileşeni temsil eden 0 ile 255 arasında bir tamsayı.

Notlar#

  • 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

Örnek#

// 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);

Üye Fonksiyonları#

color sınıfı aşağıdaki üye fonksiyonlarını içerir:

  • rgb — RGB değerlerini kullanarak rengi günceller.

  • hsv — HSV değerlerini kullanarak rengi günceller.

  • web — Bir web onaltılık renk dizesi kullanarak rengi günceller.

Herhangi bir color üye fonksiyonunu çağırmadan önce, aşağıda gösterildiği gibi color bir örnek oluşturulmalıdır:

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

rgb#

RGB değerlerini kullanarak mevcut color nesnesinin rengini günceller.

Available Functions

1 — Bir renk nesnesini paketlenmiş bir RGB değeriyle günceller.

uint32_t rgb( 
  uint32_t value );

2 — Ayrı RGB değerlerine sahip bir renk nesnesini günceller.

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

Parameters

Parametre

Tip

Tanım

value

uint32_t

Üç renk bileşeninin tamamını içeren sıkıştırılmış bir RGB değeri.

r

uint8_t

Rengin kırmızı bileşenini temsil eden 0 ile 255 arasında bir tamsayı.

g

uint8_t

Rengin yeşil bileşenini temsil eden 0 ile 255 arasında bir tamsayı.

b

uint8_t

Rengin mavi bileşenini temsil eden 0 ile 255 arasında bir tamsayı.

Return Values

Güncellenen rengin paketlenmiş RGB değerini temsil eden uint32_t değerini döndürür.

Examples
// Drive until a teal object is found
color brainColor = color(50, 200, 180);
Drivetrain.drive(forward);
while (true) {
    if (Color1.detects(brainColor)) {
        Drivetrain.stop();
        break;
    }
    wait(0.5, seconds);
}

hsv#

Mevcut color nesnesinin rengini ton, doygunluk ve parlaklık değerlerini kullanarak günceller.

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

Parameters

Parametre

Tip

Tanım

hue

uint32_t

Rengin tonunu temsil eden, 0 ile 360 ​​arasında bir tamsayı.

sat

double

Renk doygunluğunu temsil eden, 0,0 ile 1,0 arasında çift sayı.

value

double

Rengin parlaklığını temsil eden, 0,0 ile 1,0 arasında bir çift sayı.

Return Values

Güncellenmiş color nesnesine bir referans döndürür.

Examples
// Create a custom teal color
color brainColor = color(50, 200, 180);
// Change the color to magenta
brainColor.hsv(300, 0.75, 0.78);

// Drive forward until a magenta object is found
Drivetrain.drive(forward);
while (true) {
    if (Color1.detects(brainColor)) {
        Drivetrain.stop();
        break;
    }
    wait(0.5, seconds);
}

web#

Mevcut color nesnesinin rengini onaltılık veya web renk değeri kullanarak günceller.

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

Parameters

Parametre

Tip

Tanım

color

const char*

Belirli bir rengi tanımlayan onaltılık veya web renk değeri (örneğin, kırmızı için “#FF0000”).

Return Values

Güncellenmiş color nesnesine bir referans döndürür.

Examples
// Create a custom teal color
color brainColor = color(50, 200, 180);
// Change the color to magenta
brainColor.web("#AA2896");

// Drive forward until a magenta object is found
Drivetrain.drive(forward);
while (true) {
    if (Color1.detects(brainColor)) {
        Drivetrain.stop();
        break;
    }
    wait(0.5, seconds);
}