[name]
Class representing a color.
Examples
A Color can be initialised in any of the following ways:
//empty constructor - will default white
var color = new THREE.Color();
//Hexadecimal color (recommended)
var color = new THREE.Color( 0xff0000 );
//RGB string
var color = new THREE.Color("rgb(255, 0, 0)");
var color = new THREE.Color("rgb(100%, 0%, 0%)");
//X11 color name - all 140 color names are supported.
//Note the lack of CamelCase in the name
var color = new THREE.Color( 'skyblue' );
//HSL string
var color = new THREE.Color("hsl(0, 100%, 50%)");
//Seperate RGB values between 0 and 1
var color = new THREE.Color( 1, 0, 0 );
Constructor
[name]( [page:Multi r], [page:Float g], [page:Float b] )
[page:Multi r] - (optional) the red component of the color if arguments g and b are defined.
If they are not defined, it can be a [link:https://en.wikipedia.org/wiki/Web_colors#Hex_triplet hexadecimal triplet] (recommended) or a CSS-style string or another Color instance.
[page:Float g] - (optional) The green component of the color if it is defined.
[page:Float b] - (optional) The blue component of the color if it is defined.
Note that standard method of specifying color in Three is with a [link:https://en.wikipedia.org/wiki/Web_colors#Hex_triplet hexadecimal triplet], and that method is used
throughout the rest of the documentation.
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 [link:https://en.wikipedia.org/wiki/Web_colors#Hex_triplet hexadecimal triplet] representing the color (recommended).
- It can be an another Color instance.
- It can be a CSS style string. For Instance:
- 'rgb(250, 0,0)'
- 'rgb(100%,0%,0%)'
- 'hsl(0, 100%, 50%)'
- '#ff0000'
- '#f00'
- 'red'
Properties
[property:Boolean isColor]
Used to check whether this or derived classes are Colors. Default is *true*.
You should not change this, as it used internally for optimisation.
[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 add]( [page:Color color] )
Adds the RGB values of [page:Color color] to the RGB values of this color.
[method:Color addColors]( [page:Color color1], [page:Color color2] )
Sets this color's RGB values to the sum of the RGB values of [page:Color color1] and [page:Color color2].
[method:Color addScalar]( [page:Number s] )
Adds [page:Number s] to the RGB values of this color.
[method:Color clone]()
Returns a new Color with the same [page:.r r], [page:.g g] and [page:.b b] parameters a this one.
[method:Color copy]( [page:Color color] )
Copies the [page:.r r], [page:.g g] and [page:.b b] parameters from [page:Color color] in to this color.
[method:Color convertGammaToLinear]()
Converts this color from gamma to linear space (squares the values of [page:.r r], [page:.g g] and [page:.b b] ).
[method:Color convertLinearToGamma]()
Converts this color from linear to gamma space (takes the squareroot of [page:.r r], [page:.g g] and [page:.b b]).
[method:Color copyGammaToLinear]( [page:Color color], [page:Float gammaFactor] )
[page:Color color] — Color to copy.
[page:Float gammaFactor] - (optional). Default is *2.0*.
Copies given color making conversion from gamma to linear space,
by taking [page:.r r], [page:.g g] and [page:.b b] to the power of [page:Float gammaFactor].
[method:Color copyLinearToGamma]( [page:Color color], [page:Float gammaFactor] )
[page:Color color] — Color to copy.
[page:Float gammaFactor] - (optional). Default is *2.0*.
Copies given color making conversion from linear to gamma space,
by taking [page:.r r], [page:.g g] and [page:.b b] to the power of 1 / [page:Float gammaFactor].
[method:Boolean equals]( [page:Color color] )
Compares [page:Color color] with this one and returns true if they are the same, false otherwise.
[method:Color fromArray]( [page:Array array], [page:Integer offset] )
[page:Array array] - [page:Array] of float in the form [ [page:Float r], [page:Float g], [page:Float b] ].
[page:Integer offset] - An optional offset into the array.
Sets this color's components based on an array formatted like [ [page:Float r], [page:Float g], [page:Float b] ].
[method:Integer getHex]()
Returns the hexadecimal value of this color.
[method:String getHexString]()
Returns the string formatted hexadecimal value of this color.
[method:Object getHSL]( [page:Object optionalTarget] )
[page:Object optionalTarget] — (optional) if specified, adds h, s and l keys to object (if not already present)
and sets the results there, otherwise a new Object will be created.
Convert the values [page:.r r], [page:.g g] and [page:.b b] to [link:https://en.wikipedia.org/wiki/HSL_and_HSV HSL]
format and returns an object of the form:
{ h: 0, s: 0, l: 0 }
[method:String getStyle]()
Returns the value of this color as a CSS-style string. Example: 'rgb(255,0,0)'.
[method:Color lerp]( [page:Color color], [page:Float alpha] )
[page:Color color] - color to converge on.
[page:Float alpha] - interpolation factor in the closed interval [0, 1].
Linear interpolation of this colors RGB values and the RGB values of the passed 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:Color multiply]( [page:Color color] )
Multiplies this color's RGB values by given [page:Color color]'s RGB values.
[method:Color multiplyScalar]( [page:Number s] )
Multiplies this color's RGB values by [page:Number s].
[method:Color offsetHSL]( [page:Float h], [page:Float s], [page:Float l] )
Adds given [page:Float h], [page:Float s], and [page:Float l] to this color's existing values.
Internally this converts the [page:.r r], [page:.g g] and [page:.b b] values to HSL, adds
[page:Float h], [page:Float s], and [page:Float l] and then converts back to RGB.
[method:Color set]( [page:Multi value] )
[page:Multi value] - Value to set this color to.
See the Constructor above for full details of what [page:Multi value] can be.
Delegates to [page:.copy], .setStyle, or .setHex depending on input type.
[method:Color setHex]( [page:Integer hex] )
[page:Integer hex] — [link:https://en.wikipedia.org/wiki/Web_colors#Hex_triplet hexadecimal triplet] format.
Sets this color from a hexadecimal value.
[method:Color setHSL]( [page:Float h], [page:Float s], [page:Float l] )
[page:Float h] — hue value between 0.0 and 1.0
[page:Float s] — saturation value between 0.0 and 1.0
[page:Float l] — lightness value between 0.0 and 1.0
Sets color from HSL values.
[method:Color setRGB]( [page:Float r], [page:Float g], [page:Float b] )
[page:Float r] — Red channel value between 0 and 1.
[page:Float g] — Green channel value between 0 and 1.
[page:Float b] — Blue channel value between 0 and 1.
Sets this color from RGB values.
[method:Color setScalar]( [page:Float scalar] )
[page:Float scalar] — a value between 0.0 and 1.0.
Sets all three color components to the value [page:Float scalar].
[method:Color setStyle]( [page:String style] )
[page:String 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" ( or any [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color name]
- all 140 color names are supported ).
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.
Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).
[method:Color sub]( [page:Color color] )
Subtracts RGB components of the given color from the RGB components of this color.
If a component is negative, it is set to zero.
[method:Array toArray]( [page:Array array], [page:Integer offset] )
[page:Array array] - An optional array to store the color to.
[page:Integer offset] - An optional offset into the array.
Returns an array of the form [ r, g, b ].
Source
[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]