맞춤 색상#

소개#

color 클래스는 IQ(1세대) 브레인에서 색상을 정의하고 수정하는 데 사용됩니다. 색상은 RGB 값, 16진수 색상 코드, HSV 값 또는 미리 정의된 색상 상수를 사용하여 생성할 수 있습니다.

클래스 생성자#

1 — 색상이 지정되지 않은 color 객체를 생성합니다.

color();

2 — 16진수 또는 정수 값에서 color 객체를 생성합니다.

color( 
  int value );

3 — RGB 값에서 color 객체를 생성합니다.

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

클래스 소멸자#

color 객체를 파괴하고 관련 리소스를 해제합니다.

~color();

매개변수#

매개변수

유형

설명

value

int

색상 값은 16진수 RGB 정수(예: 0xFFF700)이거나 아래에 나열된 미리 정의된 색상 상수 중 하나일 수 있습니다.

r

uint8_t

빨간색 구성 요소를 나타내는 0에서 255 사이의 정수입니다.

g

uint8_t

녹색 성분을 나타내는 0부터 255까지의 정수입니다.

b

uint8_t

파란색 구성 요소를 나타내는 0에서 255 사이의 정수입니다.

메모#

  • 다음과 같은 미리 정의된 색상 상수가 지원됩니다:

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

회원 기능#

color 클래스는 다음과 같은 멤버 함수를 포함합니다.

  • rgb — RGB 값을 사용하여 색상을 업데이트합니다.

  • hsv — HSV 값을 사용하여 색상을 업데이트합니다.

  • web — 웹 16진수 색상 문자열을 사용하여 색상을 업데이트합니다.

color 멤버 함수를 호출하기 전에 아래와 같이 color 인스턴스를 생성해야 합니다.

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

rgb#

기존 color 객체의 색상을 RGB 값을 사용하여 업데이트합니다.

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

업데이트된 색상의 압축된 RGB 값을 나타내는 uint32_t 을 반환합니다.

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#

색조, 채도 및 밝기 값을 사용하여 기존 color 객체의 색상을 업데이트합니다.

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

업데이트된 color 객체에 대한 참조를 반환합니다.

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#

기존 color 객체의 색상을 16진수 또는 웹 색상 값을 사용하여 업데이트합니다.

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

Parameters

매개변수

유형

설명

color

const char*

특정 색상을 정의하는 16진수 또는 웹 색상 값(예: 빨간색의 경우 “#FF0000”).

Return Values

업데이트된 color 객체에 대한 참조를 반환합니다.

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