# B.Math.Color()

Represents a RGBA color.

To create the object use B.Math.makeColor().

## CONSTANTS:

WHITE = {r: 1.0, g: 1.0, b: 1.0, a: 1.0}

White color.

GRAY = {r: 0.5, g: 0.5, b: 0.5, a: 1.0}

Gray color.

BLACK = {r: 0.0, g: 0.0, b: 0.0, a: 1.0}

Black color.

RED = {r: 1.0, g: 0.0, b: 0.0, a: 1.0}

Red color.

GREEN = {r: 0.0, g: 1.0, b: 0.0, a: 1.0}

Green color.

BLUE = {r: 0.0, g: 0.0, b: 1.0, a: 1.0}

Blue color.

{number} r

Red component.

{number} g

Green component.

{number} b

Blue component.

{number} a

Alpha component.

## METHODS:

copy(color)

Copies a given color into this color.

color

### RETURNS:

this

clone()

Clones this color to a new color.

### RETURNS:

this

set(r, g, b, a)

Sets this color from separated components.

{number} r

{number} g

{number} b

{number} a

### RETURNS:

this

get(index)

Gets an element by its index.

{number} index

{number}

### THROWS:

{Error}

if the index is out of range

setHex(hex)

Sets RGB-components of this color from a hexadecimal value.

{number} hex

### RETURNS:

this

getHex()

Returns the hexadecimal value of this color (RGB-components).

### RETURNS:

{number}

fromArray(array, offset)

Sets this color from a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

toArray(array, offset)

Sets this color components to a part of array.

### PARAMETERS:

{Array.<number>} array

{number} [offset] = 0

### RETURNS:

{number}

new offset

clamp()

Clamps components of this color to the range [0.0, 1.0].

### RETURNS:

this

Adds a color or a scalar to this color.

### PARAMETERS:

{number | B.Math.Color} v

### RETURNS:

this

Adds two given colors and sets the result to this.

a

b

### RETURNS:

this

sub(v)

Subtracts a color or a scalar from this color.

### PARAMETERS:

{number | B.Math.Color} v

### RETURNS:

this

subColors(a, b)

Subtracts two given colors and sets the result to this.

a

b

### RETURNS:

this

mul(v)

Multiplies this color by a given color or a scalar.

### PARAMETERS:

{number | B.Math.Color} v

### RETURNS:

this

mulColors(a, b)

Multiplies two given colors and sets the result to this.

a

b

### RETURNS:

this

equal(v)

Checks for strict equality of this color and another color.

v

{boolean}