Pārlūkot izejas kodu

Some tweaks to Color.

Mr.doob 12 gadi atpakaļ
vecāks
revīzija
23f9161f43
2 mainītis faili ar 42 papildinājumiem un 38 dzēšanām
  1. 16 11
      docs/api/core/Color.html
  2. 26 27
      src/core/Color.js

+ 16 - 11
docs/api/core/Color.html

@@ -100,25 +100,22 @@
 		Based on MochiKit implementation by Bob Ippolito.
 		</div>
 
-		<h3>.setHex( [page:Integer hex] ) [page:this]</h3>
+		<h3>.getHex() [page:Integer]</h3>
 		<div>
-		hex — Color in hexadecimal.<br />
+		Returns the hexadecimal value of this color.
 		</div>
+
+		<h3>.getHexString() [page:String]</h3>
 		<div>
-		Sets this color from a hexadecimal value.
+		Returns the string formated hexadecimal value of this color.
 		</div>
 
-		<h3>.setContextStyle( [page:String contextStyle] ) [page:this]</h3>
+		<h3>.setHex( [page:Integer hex] ) [page:this]</h3>
 		<div>
-		contextStyle — Color in CSS context style format.<br />
+		hex — Color in hexadecimal.<br />
 		</div>
 		<div>
-		Sets this color from a CSS context style string.
-		</div>
-
-		<h3>.getHex() [page:Integer]</h3>
-		<div>
-		Returns the value of this color in hexadecimal.
+		Sets this color from a hexadecimal value.
 		</div>
 
 		<h3>.getContextStyle() [page:String]</h3>
@@ -127,6 +124,14 @@
 		Example: rgb(r, g, b)
 		</div>
 
+		<h3>.setContextStyle( [page:String contextStyle] ) [page:this]</h3>
+		<div>
+		contextStyle — Color in CSS context style format.<br />
+		</div>
+		<div>
+		Sets this color from a CSS context style string.
+		</div>
+
 		<h3>.clone() [page:Color]</h3>
 		<div>
 		Clones this color.

+ 26 - 27
src/core/Color.js

@@ -141,6 +141,12 @@ THREE.Color.prototype = {
 
 	},
 
+	getHex: function () {
+
+		return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
+
+	},
+
 	setHex: function ( hex ) {
 
 		hex = Math.floor( hex );
@@ -153,47 +159,30 @@ THREE.Color.prototype = {
 
 	},
 
-	setContextStyle: function ( contextStyle ) {
-
-		var color = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/i.exec(contextStyle);
-
-		this.r = parseInt(color[1], 10) / 255;
-		this.g = parseInt(color[2], 10) / 255;
-		this.b = parseInt(color[3], 10) / 255;
-
-		return this;
-
-	},
-
-	lerpSelf: function ( color, alpha ) {
-
-		this.r += ( color.r - this.r ) * alpha;
-		this.g += ( color.g - this.g ) * alpha;
-		this.b += ( color.b - this.b ) * alpha;
+	getHexString: function () {
 
-		return this;
+		return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
 
 	},
 
-	getHex: function () {
+	getContextStyle: function () {
 
-		return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
+		return 'rgb(' + ( ( this.r * 255 ) | 0 )  + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
 
 	},
 
-	getHexString: function () {
+	setContextStyle: function ( style ) {
 
-		return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
+		var color = /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/i.exec( style );
 
-	},
+		this.r = parseInt( color[ 1 ], 10 ) / 255;
+		this.g = parseInt( color[ 2 ], 10 ) / 255;
+		this.b = parseInt( color[ 3 ], 10 ) / 255;
 
-	getContextStyle: function () {
-
-		return 'rgb(' + ( ( this.r * 255 ) | 0 )  + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
+		return this;
 
 	},
 
-
 	getHSV: function ( hsv ) {
 
 		// based on MochiKit implementation by Bob Ippolito
@@ -263,6 +252,16 @@ THREE.Color.prototype = {
 
 	},
 
+	lerpSelf: function ( color, alpha ) {
+
+		this.r += ( color.r - this.r ) * alpha;
+		this.g += ( color.g - this.g ) * alpha;
+		this.b += ( color.b - this.b ) * alpha;
+
+		return this;
+
+	},
+
 	clone: function () {
 
 		return new THREE.Color().setRGB( this.r, this.g, this.b );