From 98be2a8fe40fd2178d67fcbfd143c85654ae4c6e Mon Sep 17 00:00:00 2001 From: Andrew Ray Date: Mon, 13 Jan 2014 00:31:33 -0800 Subject: [PATCH] Adding additional color constructor: Color( r, g, b ) Essentially a shorthand for new THREE.Color().setRGB( r, g, b ); --- docs/api/math/Color.html | 3 ++- src/math/Color.js | 10 +++++++--- test/unit/math/Color.js | 7 +++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/api/math/Color.html b/docs/api/math/Color.html index 982799fa1a..48ed5f01f6 100644 --- a/docs/api/math/Color.html +++ b/docs/api/math/Color.html @@ -18,6 +18,7 @@ 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( 1, 0, 0 );

Constructor

@@ -25,7 +26,7 @@

[name]( value )

- 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" + 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.

Properties

diff --git a/src/math/Color.js b/src/math/Color.js index 1428986f3e..4c31d93fa6 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -2,9 +2,9 @@ * @author mrdoob / http://mrdoob.com/ */ -THREE.Color = function ( value ) { +THREE.Color = function () { - if ( value !== undefined ) this.set( value ); + if ( arguments.length ) this.set( arguments.length === 1 ? arguments[0] : arguments ); return this; @@ -30,7 +30,11 @@ THREE.Color.prototype = { this.setStyle( value ); - } + } else if ( value.length ) { + + this.setRGB.apply( this, value ); + + } return this; diff --git a/test/unit/math/Color.js b/test/unit/math/Color.js index 9ed602388a..4229b2f415 100644 --- a/test/unit/math/Color.js +++ b/test/unit/math/Color.js @@ -7,6 +7,13 @@ test( "constructor", function(){ ok( c.b, "Blue: " + c.g ); }); +test( "rgb constructor", function(){ + var c = new THREE.Color( 1, 1, 1 ); + ok( c.r == 1, "Passed" ); + ok( c.g == 1, "Passed" ); + ok( c.b == 1, "Passed" ); +}); + test( "copyHex", function(){ var c = new THREE.Color(); var c2 = new THREE.Color(0xF5FFFA); -- GitLab