Skip to content

Commit

Permalink
fix : easing functions it not pass 0.0, 1.0 and 0.5
Browse files Browse the repository at this point in the history
Back.in() and Back.Out() now have limits. Sinusoidal.In() and .InOut() are replaced with Math.sin from Math.cos. Because 1 - Math.cos(Math.PI / 2) = 0.99999999999
and it does not snap to 1.
  • Loading branch information
MasatoMakino committed Apr 29, 2021
1 parent 2c52499 commit 273520d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Easing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ const Easing = {
},
Sinusoidal: {
In: function (amount: number): number {
return 1 - Math.cos((amount * Math.PI) / 2)
return 1 - Math.sin(((1.0 - amount) * Math.PI) / 2)
},
Out: function (amount: number): number {
return Math.sin((amount * Math.PI) / 2)
},
InOut: function (amount: number): number {
return 0.5 * (1 - Math.cos(Math.PI * amount))
return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount)))
},
},
Exponential: {
Expand Down Expand Up @@ -159,11 +159,11 @@ const Easing = {
Back: {
In: function (amount: number): number {
const s = 1.70158
return amount * amount * ((s + 1) * amount - s)
return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s)
},
Out: function (amount: number): number {
const s = 1.70158
return --amount * amount * ((s + 1) * amount + s) + 1
return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1
},
InOut: function (amount: number): number {
const s = 1.70158 * 1.525
Expand Down

0 comments on commit 273520d

Please sign in to comment.