Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color: Added lerpColors #21061

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/api/en/math/Color.html
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ <h3>[method:Color lerp]( [param:Color color], [param:Float alpha] ) </h3>
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 />
Expand Down
1 change: 1 addition & 0 deletions src/math/Color.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
10 changes: 10 additions & 0 deletions src/math/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down