From ecc4f3fe5efd0503bb9820dbaa74966fb255c69d Mon Sep 17 00:00:00 2001 From: Remi <40400644+Remi-Tribia@users.noreply.github.com> Date: Mon, 30 Jul 2018 16:53:00 +0200 Subject: [PATCH 1/5] Adding Chromatic lerp function Chromatic lerp using hsl unlike linear one using rgb --- src/math/Color.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/math/Color.js b/src/math/Color.js index 025cd4910775e4..72d2ff2a5441ba 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -540,6 +540,21 @@ Object.assign( Color.prototype, { return this; }, + + lerpChromatic: function ( color, alpha ) { + + var hslA = this.getHSL(); + var hslB = color.getHSL(); + + 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 ) { From 10bb930d488911f931175176a6ad427bf0f1fbbf Mon Sep 17 00:00:00 2001 From: Remi <40400644+Remi-Tribia@users.noreply.github.com> Date: Mon, 30 Jul 2018 17:31:38 +0200 Subject: [PATCH 2/5] Color chromatic lerp function --- src/math/Color.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math/Color.js b/src/math/Color.js index 72d2ff2a5441ba..d792a12957457d 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -540,8 +540,8 @@ Object.assign( Color.prototype, { return this; }, - - lerpChromatic: function ( color, alpha ) { + + lerpChromatic: function ( color, alpha ) { var hslA = this.getHSL(); var hslB = color.getHSL(); From 7558020bd06f0f3fda1de36c69c459f052f2682c Mon Sep 17 00:00:00 2001 From: Remi <40400644+Remi-Tribia@users.noreply.github.com> Date: Mon, 30 Jul 2018 23:07:28 +0200 Subject: [PATCH 3/5] changes to prevent console warnings --- src/math/Color.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/math/Color.js b/src/math/Color.js index d792a12957457d..5590100f05dbc5 100644 --- a/src/math/Color.js +++ b/src/math/Color.js @@ -541,20 +541,27 @@ Object.assign( Color.prototype, { }, - lerpChromatic: function ( color, alpha ) { + lerpHSL: function () { - var hslA = this.getHSL(); - var hslB = color.getHSL(); + var hslA = { h: 0, s: 0, l: 0 }; + var hslB = { h: 0, s: 0, l: 0 }; - 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 ); + return function lerpHSL( color, alpha ) { - this.setHSL( h, s, l ); + this.getHSL( hslA ); + color.getHSL( hslB ); - return this; + 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 ) { From c0ea8c21a79518e2625c818ecc9433cf2a869657 Mon Sep 17 00:00:00 2001 From: Remi <40400644+Remi-Tribia@users.noreply.github.com> Date: Wed, 1 Aug 2018 13:08:11 +0200 Subject: [PATCH 4/5] Adding lerpHSL --- docs/api/math/Color.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/api/math/Color.html b/docs/api/math/Color.html index 0f11bbd99dd881..4612b8caac29c1 100644 --- a/docs/api/math/Color.html +++ b/docs/api/math/Color.html @@ -218,6 +218,22 @@

[method:Color lerp]( [param:Color color], [param:Float alpha] )

this color and 1.0 is the first argument.

+ + +

[method:Color lerpHSL]( [param:Color color], [param:Float alpha] )

+

+ [page:Color color] - color to converge on.
+ [page:Float alpha] - interpolation factor in the closed interval [0, 1].

+ + 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. +

+ + +

[method:Color multiply]( [param:Color color] )

Multiplies this color's RGB values by the given [page:Color color]'s RGB values.

From 7f8c270e4879588db867cf48683cc62fe3aac0e8 Mon Sep 17 00:00:00 2001 From: Remi <40400644+Remi-Tribia@users.noreply.github.com> Date: Wed, 1 Aug 2018 13:08:56 +0200 Subject: [PATCH 5/5] Adding lerpHSL in doc --- docs/api/math/Color.html | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/api/math/Color.html b/docs/api/math/Color.html index 4612b8caac29c1..3941f16b121fc6 100644 --- a/docs/api/math/Color.html +++ b/docs/api/math/Color.html @@ -218,8 +218,6 @@

[method:Color lerp]( [param:Color color], [param:Float alpha] )

this color and 1.0 is the first argument.

- -

[method:Color lerpHSL]( [param:Color color], [param:Float alpha] )

[page:Color color] - color to converge on.
@@ -232,8 +230,6 @@

[method:Color lerpHSL]( [param:Color color], [param:Float alpha] )

this color and 1.0 is the first argument.

- -

[method:Color multiply]( [param:Color color] )

Multiplies this color's RGB values by the given [page:Color color]'s RGB values.