# JSDoc: Class: Color

# Class: Color

## util.Color(objopt, colorspaceopt)

#### new Color(objopt, colorspaceopt)

This class handles multiple color spaces, and offers various static methods for converting colors from one space to another.

The constructor accepts the following color representations:

- a named color, e.g. 'aliceblue' (the colorspace must be RGB)
- an hexadecimal string representation, e.g. '#FF0000' (the colorspace must be RGB)
- an hexadecimal number representation, e.g. 0xFF0000 (the colorspace must be RGB)
- a triplet of numbers, e.g. [-1, 0, 1], [0, 128, 255] (the numbers must be within the range determined by the colorspace)

Note: internally, colors are represented as a [r,g,b] triplet with r,g,b in [0,1].

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`obj` | string | number | Array.<number> | undefined | <optional> | 'black' | an object representing a color
`colorspace` | module:util.Color#COLOR_SPACE | undefined | <optional> | Color.COLOR_SPACE.RGB | the colorspace of that color

Source:
  - util/Color.js, line 10
To Do:
  - implement HSV, DKL, and LMS colorspaces

### Members

#### (readonly) COLOR_SPACE :Symbol

Color spaces.

##### Type:

- Symbol

Source:
  - util/Color.js, line 528

#### (readonly) NAMED_COLORS :string

Named colors.

##### Type:

- string

Source:
  - util/Color.js, line 553

### Methods

#### (static) hex() → {string}

Get the hexadecimal color code equivalent of this Color.

Source:
  - util/Color.js, line 173

##### Returns:

the hexadecimal color code equivalent

Type
  string

#### (static) hexToRgb(hex) → {Array.<number>}

Get the [0,1] RGB triplet equivalent of the hexadecimal color code.

##### Parameters:

Name | Type | Description
--- | --- | ---
`hex` | string | the hexadecimal color code

Source:
  - util/Color.js, line 263

##### Returns:

the [0,1] RGB triplet equivalent

Type
  Array.<number>

#### (static) hexToRgb255(hex) → {Array.<number>}

Get the [0,255] RGB triplet equivalent of the hexadecimal color code.

##### Parameters:

Name | Type | Description
--- | --- | ---
`hex` | string | the hexadecimal color code

Source:
  - util/Color.js, line 238

##### Returns:

the [0,255] RGB triplet equivalent

Type
  Array.<number>

#### (static) int() → {number}

Get the integer code equivalent of this Color.

Source:
  - util/Color.js, line 190

##### Returns:

the integer code equivalent

Type
  number

#### (static) rgb() → {Array.<number>}

Get the [0,1] RGB triplet equivalent of this Color.

Source:
  - util/Color.js, line 134

##### Returns:

the [0,1] RGB triplet equivalent

Type
  Array.<number>

#### (static) rgb255() → {Array.<number>}

Get the [0,255] RGB triplet equivalent of this Color.

Source:
  - util/Color.js, line 160

##### Returns:

the [0,255] RGB triplet equivalent

Type
  Array.<number>

#### (static) rgb255ToHex(rgb255) → {string}

Get the hexadecimal color code equivalent of the [0, 255] RGB triplet.

##### Parameters:

Name | Type | Description
--- | --- | ---
`rgb255` | Array.<number> | the [0, 255] RGB triplet

Source:
  - util/Color.js, line 279

##### Returns:

the hexadecimal color code equivalent

Type
  string

#### (static) rgb255ToInt(rgb255) → {number}

Get the integer equivalent of the [0, 255] RGB triplet.

##### Parameters:

Name | Type | Description
--- | --- | ---
`rgb255` | Array.<number> | the [0, 255] RGB triplet

Source:
  - util/Color.js, line 363

##### Returns:

the integer equivalent

Type
  number

#### (static) rgbFull() → {Array.<number>}

Get the [-1,1] RGB triplet equivalent of this Color.

Source:
  - util/Color.js, line 147

##### Returns:

the [-1,1] RGB triplet equivalent

Type
  Array.<number>

#### (static) rgbToHex(rgb) → {string}

Get the hexadecimal color code equivalent of the [0, 1] RGB triplet.

##### Parameters:

Name | Type | Description
--- | --- | ---
`rgb` | Array.<number> | the [0, 1] RGB triplet

Source:
  - util/Color.js, line 307

##### Returns:

the hexadecimal color code equivalent

Type
  string

#### (static) rgbToInt(rgb) → {number}

Get the integer equivalent of the [0, 1] RGB triplet.

##### Parameters:

Name | Type | Description
--- | --- | ---
`rgb` | Array.<number> | the [0, 1] RGB triplet

Source:
  - util/Color.js, line 335

##### Returns:

the integer equivalent

Type
  number

#### (static) toString() → {string}

String representation of the color, i.e. the hexadecimal representation.

Source:
  - util/Color.js, line 225

##### Returns:

the representation.

Type
  string