Skip to content

Commit 98be2a8

Browse files
committed
Adding additional color constructor: Color( r, g, b )
Essentially a shorthand for new THREE.Color().setRGB( r, g, b );
1 parent 5ea8a16 commit 98be2a8

3 files changed

Lines changed: 16 additions & 4 deletions

File tree

docs/api/math/Color.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ <h2>Example</h2>
1818
<code>var color = new THREE.Color();</code>
1919
<code>var color = new THREE.Color( 0xff0000 );</code>
2020
<code>var color = new THREE.Color("rgb(255,0,0)");</code>
21+
<code>var color = new THREE.Color( 1, 0, 0 );</code>
2122

2223

2324
<h2>Constructor</h2>
2425

2526

2627
<h3>[name]( value )</h3>
2728
<div>
28-
value — optional argument that sets initial color. Can be a hexadecimal or a CSS-style string, for example, "rgb(250, 0,0)", "rgb(100%,0%,0%)", "#ff0000", "#f00", or "red"
29+
value — optional argument that sets initial color. Can be a hexadecimal or a CSS-style string, for example, "rgb(250, 0,0)", "rgb(100%,0%,0%)", "#ff0000", "#f00", or "red", or three arguments that represent color channels.
2930
</div>
3031

3132
<h2>Properties</h2>

src/math/Color.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
THREE.Color = function ( value ) {
5+
THREE.Color = function () {
66

7-
if ( value !== undefined ) this.set( value );
7+
if ( arguments.length ) this.set( arguments.length === 1 ? arguments[0] : arguments );
88

99
return this;
1010

@@ -30,7 +30,11 @@ THREE.Color.prototype = {
3030

3131
this.setStyle( value );
3232

33-
}
33+
} else if ( value.length ) {
34+
35+
this.setRGB.apply( this, value );
36+
37+
}
3438

3539
return this;
3640

test/unit/math/Color.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ test( "constructor", function(){
77
ok( c.b, "Blue: " + c.g );
88
});
99

10+
test( "rgb constructor", function(){
11+
var c = new THREE.Color( 1, 1, 1 );
12+
ok( c.r == 1, "Passed" );
13+
ok( c.g == 1, "Passed" );
14+
ok( c.b == 1, "Passed" );
15+
});
16+
1017
test( "copyHex", function(){
1118
var c = new THREE.Color();
1219
var c2 = new THREE.Color(0xF5FFFA);

0 commit comments

Comments
 (0)