# [name]

Represents a color.

## Example

`var color = new THREE.Color();` `var color = new THREE.Color( 0xff0000 );` `var color = new THREE.Color("rgb(255, 0, 0)");` `var color = new THREE.Color("rgb(100%, 0%, 0%)");` `var color = new THREE.Color("hsl(0, 100%, 50%)");` `var color = new THREE.Color( 1, 0, 0 );`

## Constructor

### [name]( r, g, b )

r - the red component of the color if arguments g and b are defined. If they are not defined, it can be a hexadecimal or a CSS-style string or a Color instance.
g - The green component of the color if it is defined.
b - The blue component of the color if it is defined.
All arguments are optional. The default color is White.
When all arguments are defined then r is the red component, g is the green component and b is the blue component of the color.
When only r is defined:

- It can be a hexadecimal of the color.
- It can be an another color instance.
- It can be a CSS style. For Instance:
  - rgb(250, 0,0)
  - rgb(100%,0%,0%)
  - hsl(0, 100%, 50%)
  - #ff0000
  - #f00
  - red

## Properties

### [property:Float r]

Red channel value between 0 and 1. Default is 1.

### [property:Float g]

Green channel value between 0 and 1. Default is 1.

### [property:Float b]

Blue channel value between 0 and 1. Default is 1.

## Methods

### [method:Color set]( value ) [page:Color this]

value -- either an instance of [page:Color], a [page:Integer hexadecimal] value, or a css style [page:String string]
Delegates to .copy, .setStyle, or .setHex depending on input type.

### [method:Color copy]( [page:Color color] ) [page:Color this]

color — Color to copy.
Copies given color.

### [method:Color fromArray]( [page:Array array], [page:Integer offset] ) [page:Color this]

array -- [page:Array] [r, g, b]
offset -- [page:Integer] An optional offset into the array.
Sets this color's components based on an array formatted like [r, g, b]

### [method:Color copyGammaToLinear]( [page:Color color] ) [page:Color this]

color — Color to copy.
Copies given color making conversion from gamma to linear space.

### [method:Color copyLinearToGamma]( [page:Color color] ) [page:Color this]

color — Color to copy.
Copies given color making conversion from linear to gamma space.

### [method:Color convertGammaToLinear]() [page:Color this]

Converts this color from gamma to linear space.

### [method:Color convertLinearToGamma]() [page:Color this]

Converts this color from linear to gamma space.

### [method:Color setRGB]( [page:Float r], [page:Float g], [page:Float b] ) [page:Color this]

r — Red channel value between 0 and 1.
g — Green channel value between 0 and 1.
b — Blue channel value between 0 and 1.
Sets this color from RGB values.

### [method:Integer getHex]()

Returns the hexadecimal value of this color.

### [method:String getHexString]()

Returns the string formated hexadecimal value of this color.

### [method:Color setHex]( [page:Integer hex] ) [page:Color this]

hex — Color in hexadecimal.
Sets this color from a hexadecimal value.

### [method:Color setStyle]( [page:String style] ) [page:Color this]

style — color as a CSS-style string.
Sets this color from a CSS-style string. For example, "rgb(250, 0,0)", "rgb(100%, 0%, 0%)", "hsl(0, 100%, 50%)", "#ff0000", "#f00", or "red". Transluent colors such as "rgba(255, 0, 0, 0.5)" and "hsla(0, 100%, 50%, 0.5)" are also accepted, but the alpha-channel coordinate will be discarded.

### [method:String getStyle]()

Returns the value of this color as a CSS-style string. Example: rgb(255,0,0)

### [method:Color setHSL]( [page:Float h], [page:Float s], [page:Float l] ) [page:Color this]

h — hue value between 0.0 and 1.0
s — saturation value between 0.0 and 1.0
l — lightness value between 0.0 and 1.0
Sets color from hsl

### [method:Object getHSL]() [page:Object hsl]

Returns an object with properties h, s, and l.

### [method:Color offsetHSL]( [page:Float h], [page:Float s], [page:Float l] ) [page:Color this]

Adds given h, s, and l to this color's existing h, s, and l values.

### [method:Color sub]( [page:Color color] ) [page:Color this]

Subtracts rgb components of given color from rgb components of this color. If a component is negative, it is set to zero.

### [method:Color add]( [page:Color color] ) [page:Color this]

Adds rgb values of given color to rgb values of this color

### [method:Color addColors]( [page:Color color1], [page:Color color2] ) [page:Color this]

Sets this color to the sum of color1 and color2

### [method:Color addScalar]( [page:Number s] ) [page:Color this]

Adds s to the rgb values of this color

### [method:Color multiply]( [page:Color color] ) [page:Color this]

Multiplies this color's rgb values by given color's rgb values

### [method:Color multiplyScalar]( [page:Number s] ) [page:Color this]

Multiplies this color's rgb values by s

### [method:Color lerp]( [page:Color color], alpha ) [page:Color this]

alpha -- a number between 0 and 1.
Linear interpolation of this colors rgb values and the rgb values of the first argument. The alpha argument can be thought of as the percent between the two colors, where 0 is this color and 1 is the first argument.

### [method:Boolean equals]( [page:Color c] ) [page:Color this]

Compares this color and c and returns true if they are the same, false otherwise.

### [method:Color clone]() [page:Color this]

Clones this color.

### [method:Array toArray]( [page:Array array], [page:Integer offset] ) [page:Color this]

array -- An optional array to store the color to.
offset -- An optional offset into the array.
Returns an array [r,g,b]

## Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]