Browse Source

Merge pull request #14589 from Remi-Tribia/dev

Color chromatic lerp function
Mr.doob 7 years ago
parent
commit
e8443b2e0d
2 changed files with 34 additions and 0 deletions
  1. 12 0
      docs/api/math/Color.html
  2. 22 0
      src/math/Color.js

+ 12 - 0
docs/api/math/Color.html

@@ -218,6 +218,18 @@ var color = new THREE.Color( 1, 0, 0 );
 		this color and 1.0 is the first argument.
 		</p>
 
+		<h3>[method:Color lerpHSL]( [param:Color color], [param:Float alpha] ) </h3>
+		<p>
+		[page:Color color] - color to converge on.<br />
+		[page:Float alpha] - interpolation factor in the closed interval [0, 1].<br /><br />
+
+		Linearly interpolates this color's HSL values toward the HSL values of the passed argument.
+		It differs from the classic [page:.lerp] by not interpolating straight from one color to the other,
+		but instead going through all the hues in between those two colors.
+		The alpha argument can be thought of as the ratio between the two colors, where 0.0 is
+		this color and 1.0 is the first argument.
+		</p>
+
 		<h3>[method:Color multiply]( [param:Color color] ) </h3>
 		<p>Multiplies this color's RGB values by the given [page:Color color]'s RGB values.</p>
 

+ 22 - 0
src/math/Color.js

@@ -541,6 +541,28 @@ Object.assign( Color.prototype, {
 
 	},
 
+	lerpHSL: function () {
+
+		var hslA = { h: 0, s: 0, l: 0 };
+		var hslB = { h: 0, s: 0, l: 0 };
+
+		return function lerpHSL( color, alpha ) {
+
+			this.getHSL( hslA );
+			color.getHSL( hslB );
+
+			var h = _Math.lerp( hslA.h, hslB.h, alpha );
+			var s = _Math.lerp( hslA.s, hslB.s, alpha );
+			var l = _Math.lerp( hslA.l, hslB.l, alpha );
+
+			this.setHSL( h, s, l );
+
+			return this;
+
+		};
+
+	}(),
+
 	equals: function ( c ) {
 
 		return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );