提交 20323db1 编写于 作者: M Mr.doob

Merge branch 'color-constructor' of https://github.com/DelvarWorld/three.js into dev

...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<code>var color = new THREE.Color();</code> <code>var color = new THREE.Color();</code>
<code>var color = new THREE.Color( 0xff0000 );</code> <code>var color = new THREE.Color( 0xff0000 );</code>
<code>var color = new THREE.Color("rgb(255,0,0)");</code> <code>var color = new THREE.Color("rgb(255,0,0)");</code>
<code>var color = new THREE.Color( 1, 0, 0 );</code>
<h2>Constructor</h2> <h2>Constructor</h2>
...@@ -25,7 +26,7 @@ ...@@ -25,7 +26,7 @@
<h3>[name]( value )</h3> <h3>[name]( value )</h3>
<div> <div>
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.
</div> </div>
<h2>Properties</h2> <h2>Properties</h2>
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
* @author mrdoob / http://mrdoob.com/ * @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; return this;
...@@ -30,7 +30,11 @@ THREE.Color.prototype = { ...@@ -30,7 +30,11 @@ THREE.Color.prototype = {
this.setStyle( value ); this.setStyle( value );
} } else if ( value.length ) {
this.setRGB.apply( this, value );
}
return this; return this;
......
...@@ -7,6 +7,13 @@ test( "constructor", function(){ ...@@ -7,6 +7,13 @@ test( "constructor", function(){
ok( c.b, "Blue: " + c.b ); ok( c.b, "Blue: " + c.b );
}); });
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(){ test( "copyHex", function(){
var c = new THREE.Color(); var c = new THREE.Color();
var c2 = new THREE.Color(0xF5FFFA); var c2 = new THREE.Color(0xF5FFFA);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册