Bladeren bron

Color: Added lerpColors.

Mr.doob 4 jaren geleden
bovenliggende
commit
622a475a2d
3 gewijzigde bestanden met toevoegingen van 22 en 0 verwijderingen
  1. 11 0
      docs/api/en/math/Color.html
  2. 1 0
      src/math/Color.d.ts
  3. 10 0
      src/math/Color.js

+ 11 - 0
docs/api/en/math/Color.html

@@ -218,6 +218,17 @@ const color7 = new THREE.Color( 1, 0, 0 );
 		this color and 1.0 is the first argument.
 		</p>
 
+		<h3>[method:this lerpColors]( [param:Color color1], [param:Color color2], [param:Float alpha] )</h3>
+		<p>
+		[page:Color color1] - the starting [page:Color].<br />
+		[page:Color color2] - [page:Color] to interpolate towards.<br />
+		[page:Float alpha] - interpolation factor, typically in the closed interval [0, 1].<br /><br />
+
+		Sets this color to be the color linearly interpolated between [page:Color color1] and
+		[page:Color color2] where alpha is the percent distance along the line connecting the two colors
+		- alpha = 0 will be [page:Color color1], and alpha = 1 will be [page:Color color2].
+		</p>
+
 		<h3>[method:Color lerpHSL]( [param:Color color], [param:Float alpha] ) </h3>
 		<p>
 		[page:Color color] - color to converge on.<br />

+ 1 - 0
src/math/Color.d.ts

@@ -156,6 +156,7 @@ export class Color {
 	multiply( color: Color ): this;
 	multiplyScalar( s: number ): this;
 	lerp( color: Color, alpha: number ): this;
+	lerpColors( color1: Color, color2: Color, alpha: number ): this;
 	lerpHSL( color: Color, alpha: number ): this;
 	equals( color: Color ): boolean;
 

+ 10 - 0
src/math/Color.js

@@ -524,6 +524,16 @@ class Color {
 
 	}
 
+	lerpColors( color1, color2, alpha ) {
+
+		this.r = color1.r + ( color2.r - color1.r ) * alpha;
+		this.g = color1.g + ( color2.g - color1.g ) * alpha;
+		this.b = color1.b + ( color2.b - color1.b ) * alpha;
+
+		return this;
+
+	}
+
 	lerpHSL( color, alpha ) {
 
 		this.getHSL( _hslA );