LCOV - code coverage report
Current view: top level - modules/script/tweener - equations.js (source / functions) Coverage Total Hit
Test: gjs- Code Coverage Lines: 2.4 % 123 3
Test Date: 2024-04-20 17:42:51 Functions: 9.3 % 43 4
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1.8 % 112 2

             Branch data     Line data    Source code
       1                 :           1 : /* -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil; -*- */
       2                 :             : /* eslint-disable no-unused-vars */
       3                 :             : // SPDX-License-Identifier: BSD-3-Clause
       4                 :             : // SPDX-FileCopyrightText: 2008 litl, LLC.
       5                 :             : // SPDX-FileCopyrightText: 2001 Robert Penner
       6                 :             : 
       7                 :             : /**
       8                 :             :  * Equations
       9                 :             :  * Main equations for the Tweener class
      10                 :             :  *
      11                 :             :  * @author              Zeh Fernando, Nate Chatellier
      12                 :             :  * @version             1.0.2
      13                 :             :  */
      14                 :             : 
      15                 :             : /* exported easeInBack, easeInBounce, easeInCirc, easeInCubic, easeInElastic,
      16                 :             : easeInExpo, easeInOutBack, easeInOutBounce, easeInOutCirc, easeInOutCubic,
      17                 :             : easeInOutElastic, easeInOutExpo, easeInOutQuad, easeInOutQuart, easeInOutQuint,
      18                 :             : easeInOutSine, easeInQuad, easeInQuart, easeInQuint, easeInSine, easeNone,
      19                 :             : easeOutBack, easeOutBounce, easeOutCirc, easeOutCubic, easeOutElastic,
      20                 :             : easeOutExpo, easeOutInBack, easeOutInBounce, easeOutInCirc, easeOutInCubic,
      21                 :             : easeOutInElastic, easeOutInExpo, easeOutInQuad, easeOutInQuart, easeOutInQuint,
      22                 :             : easeOutInSine, easeOutQuad, easeOutQuart, easeOutQuint, easeOutSine, linear */
      23                 :             : 
      24                 :             : // ==================================================================================================================================
      25                 :             : // TWEENING EQUATIONS functions -----------------------------------------------------------------------------------------------------
      26                 :             : // (the original equations are Robert Penner's work as mentioned on the disclaimer)
      27                 :             : 
      28                 :             : /**
      29                 :             :  * Easing equation function for a simple linear tweening, with no easing.
      30                 :             :  *
      31                 :             :  * @param t             Current time (in frames or seconds).
      32                 :             :  * @param b             Starting value.
      33                 :             :  * @param c             Change needed in value.
      34                 :             :  * @param d             Expected easing duration (in frames or seconds).
      35                 :             :  * @return              The correct value.
      36                 :             :  */
      37                 :         642 : function easeNone(t, b, c, d, pParams) {
      38                 :         642 :     return c * t / d + b;
      39                 :             : }
      40                 :             : 
      41                 :             : /* Useful alias */
      42                 :         642 : function linear(t, b, c, d, pParams) {
      43                 :         642 :     return easeNone(t, b, c, d, pParams);
      44                 :             : }
      45                 :             : 
      46                 :             : /**
      47                 :             :  * Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
      48                 :             :  *
      49                 :             :  * @param t             Current time (in frames or seconds).
      50                 :             :  * @param b             Starting value.
      51                 :             :  * @param c             Change needed in value.
      52                 :             :  * @param d             Expected easing duration (in frames or seconds).
      53                 :             :  * @return              The correct value.
      54                 :             :  */
      55                 :           0 : function easeInQuad(t, b, c, d, pParams) {
      56                 :           0 :     return c * (t /= d) * t + b;
      57                 :             : }
      58                 :             : 
      59                 :             : /**
      60                 :             :  * Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
      61                 :             :  *
      62                 :             :  * @param t             Current time (in frames or seconds).
      63                 :             :  * @param b             Starting value.
      64                 :             :  * @param c             Change needed in value.
      65                 :             :  * @param d             Expected easing duration (in frames or seconds).
      66                 :             :  * @return              The correct value.
      67                 :             :  */
      68                 :           0 : function easeOutQuad(t, b, c, d, pParams) {
      69                 :           0 :     return -c * (t /= d) * (t - 2) + b;
      70                 :             : }
      71                 :             : 
      72                 :             : /**
      73                 :             :  * Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
      74                 :             :  *
      75                 :             :  * @param t             Current time (in frames or seconds).
      76                 :             :  * @param b             Starting value.
      77                 :             :  * @param c             Change needed in value.
      78                 :             :  * @param d             Expected easing duration (in frames or seconds).
      79                 :             :  * @return              The correct value.
      80                 :             :  */
      81                 :           0 : function easeInOutQuad(t, b, c, d, pParams) {
      82         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
      83                 :           0 :         return c / 2 * t * t + b;
      84                 :           0 :     return -c / 2 * (--t * (t - 2) - 1) + b;
      85                 :             : }
      86                 :             : 
      87                 :             : /**
      88                 :             :  * Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
      89                 :             :  *
      90                 :             :  * @param t             Current time (in frames or seconds).
      91                 :             :  * @param b             Starting value.
      92                 :             :  * @param c             Change needed in value.
      93                 :             :  * @param d             Expected easing duration (in frames or seconds).
      94                 :             :  * @return              The correct value.
      95                 :             :  */
      96                 :           0 : function easeOutInQuad(t, b, c, d, pParams) {
      97         [ #  # ]:           0 :     if (t < d / 2)
      98                 :           0 :         return easeOutQuad(t * 2, b, c / 2, d, pParams);
      99                 :           0 :     return easeInQuad(t * 2 - d, b + c / 2, c / 2, d, pParams);
     100                 :             : }
     101                 :             : 
     102                 :             : /**
     103                 :             :  * Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
     104                 :             :  *
     105                 :             :  * @param t             Current time (in frames or seconds).
     106                 :             :  * @param b             Starting value.
     107                 :             :  * @param c             Change needed in value.
     108                 :             :  * @param d             Expected easing duration (in frames or seconds).
     109                 :             :  * @return              The correct value.
     110                 :             :  */
     111                 :           0 : function easeInCubic(t, b, c, d, pParams) {
     112                 :           0 :     return c * (t /= d) * t * t + b;
     113                 :             : }
     114                 :             : 
     115                 :             : /**
     116                 :             :  * Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
     117                 :             :  *
     118                 :             :  * @param t             Current time (in frames or seconds).
     119                 :             :  * @param b             Starting value.
     120                 :             :  * @param c             Change needed in value.
     121                 :             :  * @param d             Expected easing duration (in frames or seconds).
     122                 :             :  * @return              The correct value.
     123                 :             :  */
     124                 :           0 : function easeOutCubic(t, b, c, d, pParams) {
     125                 :           0 :     return c * ((t = t / d - 1) * t * t + 1) + b;
     126                 :             : }
     127                 :             : 
     128                 :             : /**
     129                 :             :  * Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
     130                 :             :  *
     131                 :             :  * @param t             Current time (in frames or seconds).
     132                 :             :  * @param b             Starting value.
     133                 :             :  * @param c             Change needed in value.
     134                 :             :  * @param d             Expected easing duration (in frames or seconds).
     135                 :             :  * @return              The correct value.
     136                 :             :  */
     137                 :           0 : function easeInOutCubic(t, b, c, d, pParams) {
     138         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     139                 :           0 :         return c / 2 * t * t * t + b;
     140                 :           0 :     return c / 2 * ((t -= 2) * t * t + 2) + b;
     141                 :             : }
     142                 :             : 
     143                 :             : /**
     144                 :             :  * Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
     145                 :             :  *
     146                 :             :  * @param t             Current time (in frames or seconds).
     147                 :             :  * @param b             Starting value.
     148                 :             :  * @param c             Change needed in value.
     149                 :             :  * @param d             Expected easing duration (in frames or seconds).
     150                 :             :  * @return              The correct value.
     151                 :             :  */
     152                 :           0 : function easeOutInCubic(t, b, c, d, pParams) {
     153         [ #  # ]:           0 :     if (t < d / 2)
     154                 :           0 :         return easeOutCubic(t * 2, b, c / 2, d, pParams);
     155                 :           0 :     return easeInCubic(t * 2 - d, b + c / 2, c / 2, d, pParams);
     156                 :             : }
     157                 :             : 
     158                 :             : /**
     159                 :             :  * Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
     160                 :             :  *
     161                 :             :  * @param t             Current time (in frames or seconds).
     162                 :             :  * @param b             Starting value.
     163                 :             :  * @param c             Change needed in value.
     164                 :             :  * @param d             Expected easing duration (in frames or seconds).
     165                 :             :  * @return              The correct value.
     166                 :             :  */
     167                 :           0 : function easeInQuart(t, b, c, d, pParams) {
     168                 :           0 :     return c * (t /= d) * t * t * t + b;
     169                 :             : }
     170                 :             : 
     171                 :             : /**
     172                 :             :  * Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
     173                 :             :  *
     174                 :             :  * @param t             Current time (in frames or seconds).
     175                 :             :  * @param b             Starting value.
     176                 :             :  * @param c             Change needed in value.
     177                 :             :  * @param d             Expected easing duration (in frames or seconds).
     178                 :             :  * @return              The correct value.
     179                 :             :  */
     180                 :           0 : function easeOutQuart(t, b, c, d, pParams) {
     181                 :           0 :     return -c * ((t = t / d - 1) * t * t * t - 1) + b;
     182                 :             : }
     183                 :             : 
     184                 :             : /**
     185                 :             :  * Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
     186                 :             :  *
     187                 :             :  * @param t             Current time (in frames or seconds).
     188                 :             :  * @param b             Starting value.
     189                 :             :  * @param c             Change needed in value.
     190                 :             :  * @param d             Expected easing duration (in frames or seconds).
     191                 :             :  * @return              The correct value.
     192                 :             :  */
     193                 :           0 : function easeInOutQuart(t, b, c, d, pParams) {
     194         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     195                 :           0 :         return c / 2 * t * t * t * t + b;
     196                 :           0 :     return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
     197                 :             : }
     198                 :             : 
     199                 :             : /**
     200                 :             :  * Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
     201                 :             :  *
     202                 :             :  * @param t             Current time (in frames or seconds).
     203                 :             :  * @param b             Starting value.
     204                 :             :  * @param c             Change needed in value.
     205                 :             :  * @param d             Expected easing duration (in frames or seconds).
     206                 :             :  * @return              The correct value.
     207                 :             :  */
     208                 :           0 : function easeOutInQuart(t, b, c, d, pParams) {
     209         [ #  # ]:           0 :     if (t < d / 2)
     210                 :           0 :         return easeOutQuart(t * 2, b, c / 2, d, pParams);
     211                 :           0 :     return easeInQuart(t * 2 - d, b + c / 2, c / 2, d, pParams);
     212                 :             : }
     213                 :             : 
     214                 :             : /**
     215                 :             :  * Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
     216                 :             :  *
     217                 :             :  * @param t             Current time (in frames or seconds).
     218                 :             :  * @param b             Starting value.
     219                 :             :  * @param c             Change needed in value.
     220                 :             :  * @param d             Expected easing duration (in frames or seconds).
     221                 :             :  * @return              The correct value.
     222                 :             :  */
     223                 :           0 : function easeInQuint(t, b, c, d, pParams) {
     224                 :           0 :     return c * (t /= d) * t * t * t * t + b;
     225                 :             : }
     226                 :             : 
     227                 :             : /**
     228                 :             :  * Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
     229                 :             :  *
     230                 :             :  * @param t             Current time (in frames or seconds).
     231                 :             :  * @param b             Starting value.
     232                 :             :  * @param c             Change needed in value.
     233                 :             :  * @param d             Expected easing duration (in frames or seconds).
     234                 :             :  * @return              The correct value.
     235                 :             :  */
     236                 :           0 : function easeOutQuint(t, b, c, d, pParams) {
     237                 :           0 :     return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
     238                 :             : }
     239                 :             : 
     240                 :             : /**
     241                 :             :  * Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
     242                 :             :  *
     243                 :             :  * @param t             Current time (in frames or seconds).
     244                 :             :  * @param b             Starting value.
     245                 :             :  * @param c             Change needed in value.
     246                 :             :  * @param d             Expected easing duration (in frames or seconds).
     247                 :             :  * @return              The correct value.
     248                 :             :  */
     249                 :           0 : function easeInOutQuint(t, b, c, d, pParams) {
     250         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     251                 :           0 :         return c / 2 * t * t * t * t * t + b;
     252                 :           0 :     return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
     253                 :             : }
     254                 :             : 
     255                 :             : /**
     256                 :             :  * Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
     257                 :             :  *
     258                 :             :  * @param t             Current time (in frames or seconds).
     259                 :             :  * @param b             Starting value.
     260                 :             :  * @param c             Change needed in value.
     261                 :             :  * @param d             Expected easing duration (in frames or seconds).
     262                 :             :  * @return              The correct value.
     263                 :             :  */
     264                 :           0 : function easeOutInQuint(t, b, c, d, pParams) {
     265         [ #  # ]:           0 :     if (t < d / 2)
     266                 :           0 :         return easeOutQuint(t * 2, b, c / 2, d, pParams);
     267                 :           0 :     return easeInQuint(t * 2 - d, b + c / 2, c / 2, d, pParams);
     268                 :             : }
     269                 :             : 
     270                 :             : /**
     271                 :             :  * Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
     272                 :             :  *
     273                 :             :  * @param t             Current time (in frames or seconds).
     274                 :             :  * @param b             Starting value.
     275                 :             :  * @param c             Change needed in value.
     276                 :             :  * @param d             Expected easing duration (in frames or seconds).
     277                 :             :  * @return              The correct value.
     278                 :             :  */
     279                 :           0 : function easeInSine(t, b, c, d, pParams) {
     280                 :           0 :     return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
     281                 :             : }
     282                 :             : 
     283                 :             : /**
     284                 :             :  * Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
     285                 :             :  *
     286                 :             :  * @param t             Current time (in frames or seconds).
     287                 :             :  * @param b             Starting value.
     288                 :             :  * @param c             Change needed in value.
     289                 :             :  * @param d             Expected easing duration (in frames or seconds).
     290                 :             :  * @return              The correct value.
     291                 :             :  */
     292                 :           0 : function easeOutSine(t, b, c, d, pParams) {
     293                 :           0 :     return c * Math.sin(t / d * (Math.PI / 2)) + b;
     294                 :             : }
     295                 :             : 
     296                 :             : /**
     297                 :             :  * Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
     298                 :             :  *
     299                 :             :  * @param t             Current time (in frames or seconds).
     300                 :             :  * @param b             Starting value.
     301                 :             :  * @param c             Change needed in value.
     302                 :             :  * @param d             Expected easing duration (in frames or seconds).
     303                 :             :  * @return              The correct value.
     304                 :             :  */
     305                 :           0 : function easeInOutSine(t, b, c, d, pParams) {
     306                 :           0 :     return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
     307                 :             : }
     308                 :             : 
     309                 :             : /**
     310                 :             :  * Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
     311                 :             :  *
     312                 :             :  * @param t             Current time (in frames or seconds).
     313                 :             :  * @param b             Starting value.
     314                 :             :  * @param c             Change needed in value.
     315                 :             :  * @param d             Expected easing duration (in frames or seconds).
     316                 :             :  * @return              The correct value.
     317                 :             :  */
     318                 :           0 : function easeOutInSine(t, b, c, d, pParams) {
     319         [ #  # ]:           0 :     if (t < d / 2)
     320                 :           0 :         return easeOutSine(t * 2, b, c / 2, d, pParams);
     321                 :           0 :     return easeInSine(t * 2 - d, b + c / 2, c / 2, d, pParams);
     322                 :             : }
     323                 :             : 
     324                 :             : /**
     325                 :             :  * Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
     326                 :             :  *
     327                 :             :  * @param t             Current time (in frames or seconds).
     328                 :             :  * @param b             Starting value.
     329                 :             :  * @param c             Change needed in value.
     330                 :             :  * @param d             Expected easing duration (in frames or seconds).
     331                 :             :  * @return              The correct value.
     332                 :             :  */
     333                 :           0 : function easeInExpo(t, b, c, d, pParams) {
     334         [ #  # ]:           0 :     return t <= 0 ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
     335                 :             : }
     336                 :             : 
     337                 :             : /**
     338                 :             :  * Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
     339                 :             :  *
     340                 :             :  * @param t             Current time (in frames or seconds).
     341                 :             :  * @param b             Starting value.
     342                 :             :  * @param c             Change needed in value.
     343                 :             :  * @param d             Expected easing duration (in frames or seconds).
     344                 :             :  * @return              The correct value.
     345                 :             :  */
     346                 :          99 : function easeOutExpo(t, b, c, d, pParams) {
     347         [ +  + ]:          99 :     return t >= d ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
     348                 :             : }
     349                 :             : 
     350                 :             : /**
     351                 :             :  * Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
     352                 :             :  *
     353                 :             :  * @param t             Current time (in frames or seconds).
     354                 :             :  * @param b             Starting value.
     355                 :             :  * @param c             Change needed in value.
     356                 :             :  * @param d             Expected easing duration (in frames or seconds).
     357                 :             :  * @return              The correct value.
     358                 :             :  */
     359                 :           0 : function easeInOutExpo(t, b, c, d, pParams) {
     360         [ #  # ]:           0 :     if (t <= 0)
     361                 :           0 :         return b;
     362         [ #  # ]:           0 :     if (t >= d)
     363                 :           0 :         return b + c;
     364         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     365                 :           0 :         return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
     366                 :           0 :     return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
     367                 :             : }
     368                 :             : 
     369                 :             : /**
     370                 :             :  * Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
     371                 :             :  *
     372                 :             :  * @param t             Current time (in frames or seconds).
     373                 :             :  * @param b             Starting value.
     374                 :             :  * @param c             Change needed in value.
     375                 :             :  * @param d             Expected easing duration (in frames or seconds).
     376                 :             :  * @return              The correct value.
     377                 :             :  */
     378                 :           0 : function easeOutInExpo(t, b, c, d, pParams) {
     379         [ #  # ]:           0 :     if (t < d / 2)
     380                 :           0 :         return easeOutExpo(t * 2, b, c / 2, d, pParams);
     381                 :           0 :     return easeInExpo(t * 2 - d, b + c / 2, c / 2, d, pParams);
     382                 :             : }
     383                 :             : 
     384                 :             : /**
     385                 :             :  * Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
     386                 :             :  *
     387                 :             :  * @param t             Current time (in frames or seconds).
     388                 :             :  * @param b             Starting value.
     389                 :             :  * @param c             Change needed in value.
     390                 :             :  * @param d             Expected easing duration (in frames or seconds).
     391                 :             :  * @return              The correct value.
     392                 :             :  */
     393                 :           0 : function easeInCirc(t, b, c, d, pParams) {
     394                 :           0 :     return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
     395                 :             : }
     396                 :             : 
     397                 :             : /**
     398                 :             :  * Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
     399                 :             :  *
     400                 :             :  * @param t             Current time (in frames or seconds).
     401                 :             :  * @param b             Starting value.
     402                 :             :  * @param c             Change needed in value.
     403                 :             :  * @param d             Expected easing duration (in frames or seconds).
     404                 :             :  * @return              The correct value.
     405                 :             :  */
     406                 :           0 : function easeOutCirc(t, b, c, d, pParams) {
     407                 :           0 :     return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
     408                 :             : }
     409                 :             : 
     410                 :             : /**
     411                 :             :  * Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
     412                 :             :  *
     413                 :             :  * @param t             Current time (in frames or seconds).
     414                 :             :  * @param b             Starting value.
     415                 :             :  * @param c             Change needed in value.
     416                 :             :  * @param d             Expected easing duration (in frames or seconds).
     417                 :             :  * @return              The correct value.
     418                 :             :  */
     419                 :           0 : function easeInOutCirc(t, b, c, d, pParams) {
     420         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     421                 :           0 :         return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
     422                 :           0 :     return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
     423                 :             : }
     424                 :             : 
     425                 :             : /**
     426                 :             :  * Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
     427                 :             :  *
     428                 :             :  * @param t             Current time (in frames or seconds).
     429                 :             :  * @param b             Starting value.
     430                 :             :  * @param c             Change needed in value.
     431                 :             :  * @param d             Expected easing duration (in frames or seconds).
     432                 :             :  * @return              The correct value.
     433                 :             :  */
     434                 :           0 : function easeOutInCirc(t, b, c, d, pParams) {
     435         [ #  # ]:           0 :     if (t < d / 2)
     436                 :           0 :         return easeOutCirc(t * 2, b, c / 2, d, pParams);
     437                 :           0 :     return easeInCirc(t * 2 - d, b + c / 2, c / 2, d, pParams);
     438                 :             : }
     439                 :             : 
     440                 :             : /**
     441                 :             :  * Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
     442                 :             :  *
     443                 :             :  * @param t             Current time (in frames or seconds).
     444                 :             :  * @param b             Starting value.
     445                 :             :  * @param c             Change needed in value.
     446                 :             :  * @param d             Expected easing duration (in frames or seconds).
     447                 :             :  * @param a             Amplitude.
     448                 :             :  * @param p             Period.
     449                 :             :  * @return              The correct value.
     450                 :             :  */
     451                 :           0 : function easeInElastic(t, b, c, d, pParams) {
     452         [ #  # ]:           0 :     if (t <= 0)
     453                 :           0 :         return b;
     454         [ #  # ]:           0 :     if ((t /= d) >= 1)
     455                 :           0 :         return b + c;
     456 [ #  # ][ #  # ]:           0 :     var p = !pParams || isNaN(pParams.period) ? d * .3 : pParams.period;
     457                 :             :     var s;
     458 [ #  # ][ #  # ]:           0 :     var a = !pParams || isNaN(pParams.amplitude) ? 0 : pParams.amplitude;
     459 [ #  # ][ #  # ]:           0 :     if (!a || a < Math.abs(c)) {
     460                 :           0 :         a = c;
     461                 :           0 :         s = p / 4;
     462                 :             :     } else {
     463                 :           0 :         s = p / (2 * Math.PI) * Math.asin(c / a);
     464                 :             :     }
     465                 :           0 :     return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
     466                 :             : }
     467                 :             : 
     468                 :             : /**
     469                 :             :  * Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
     470                 :             :  *
     471                 :             :  * @param t             Current time (in frames or seconds).
     472                 :             :  * @param b             Starting value.
     473                 :             :  * @param c             Change needed in value.
     474                 :             :  * @param d             Expected easing duration (in frames or seconds).
     475                 :             :  * @param a             Amplitude.
     476                 :             :  * @param p             Period.
     477                 :             :  * @return              The correct value.
     478                 :             :  */
     479                 :           0 : function easeOutElastic(t, b, c, d, pParams) {
     480         [ #  # ]:           0 :     if (t <= 0)
     481                 :           0 :         return b;
     482         [ #  # ]:           0 :     if ((t /= d) >= 1)
     483                 :           0 :         return b + c;
     484 [ #  # ][ #  # ]:           0 :     var p = !pParams || isNaN(pParams.period) ? d * .3 : pParams.period;
     485                 :             :     var s;
     486 [ #  # ][ #  # ]:           0 :     var a = !pParams || isNaN(pParams.amplitude) ? 0 : pParams.amplitude;
     487 [ #  # ][ #  # ]:           0 :     if (!a || a < Math.abs(c)) {
     488                 :           0 :         a = c;
     489                 :           0 :         s = p / 4;
     490                 :             :     } else {
     491                 :           0 :         s = p / (2 * Math.PI) * Math.asin(c / a);
     492                 :             :     }
     493                 :           0 :     return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
     494                 :             : }
     495                 :             : 
     496                 :             : /**
     497                 :             :  * Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
     498                 :             :  *
     499                 :             :  * @param t             Current time (in frames or seconds).
     500                 :             :  * @param b             Starting value.
     501                 :             :  * @param c             Change needed in value.
     502                 :             :  * @param d             Expected easing duration (in frames or seconds).
     503                 :             :  * @param a             Amplitude.
     504                 :             :  * @param p             Period.
     505                 :             :  * @return              The correct value.
     506                 :             :  */
     507                 :           0 : function easeInOutElastic(t, b, c, d, pParams) {
     508         [ #  # ]:           0 :     if (t <= 0)
     509                 :           0 :         return b;
     510         [ #  # ]:           0 :     if ((t /= d / 2) >= 2)
     511                 :           0 :         return b + c;
     512 [ #  # ][ #  # ]:           0 :     var p = !pParams || isNaN(pParams.period) ? d * (.3 * 1.5) : pParams.period;
     513                 :             :     var s;
     514 [ #  # ][ #  # ]:           0 :     var a = !pParams || isNaN(pParams.amplitude) ? 0 : pParams.amplitude;
     515 [ #  # ][ #  # ]:           0 :     if (!a || a < Math.abs(c)) {
     516                 :           0 :         a = c;
     517                 :           0 :         s = p / 4;
     518                 :             :     } else {
     519                 :           0 :         s = p / (2 * Math.PI) * Math.asin(c / a);
     520                 :             :     }
     521         [ #  # ]:           0 :     if (t < 1)
     522                 :           0 :         return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
     523                 :           0 :     return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
     524                 :             : }
     525                 :             : 
     526                 :             : /**
     527                 :             :  * Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
     528                 :             :  *
     529                 :             :  * @param t             Current time (in frames or seconds).
     530                 :             :  * @param b             Starting value.
     531                 :             :  * @param c             Change needed in value.
     532                 :             :  * @param d             Expected easing duration (in frames or seconds).
     533                 :             :  * @param a             Amplitude.
     534                 :             :  * @param p             Period.
     535                 :             :  * @return              The correct value.
     536                 :             :  */
     537                 :           0 : function easeOutInElastic(t, b, c, d, pParams) {
     538         [ #  # ]:           0 :     if (t < d / 2)
     539                 :           0 :         return easeOutElastic(t * 2, b, c / 2, d, pParams);
     540                 :           0 :     return easeInElastic(t * 2 - d, b + c / 2, c / 2, d, pParams);
     541                 :             : }
     542                 :             : 
     543                 :             : /**
     544                 :             :  * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
     545                 :             :  *
     546                 :             :  * @param t             Current time (in frames or seconds).
     547                 :             :  * @param b             Starting value.
     548                 :             :  * @param c             Change needed in value.
     549                 :             :  * @param d             Expected easing duration (in frames or seconds).
     550                 :             :  * @param s             Overshoot amount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
     551                 :             :  * @return              The correct value.
     552                 :             :  */
     553                 :           0 : function easeInBack(t, b, c, d, pParams) {
     554 [ #  # ][ #  # ]:           0 :     var s = !pParams || isNaN(pParams.overshoot) ? 1.70158 : pParams.overshoot;
     555                 :           0 :     return c * (t /= d) * t * ((s + 1) * t - s) + b;
     556                 :             : }
     557                 :             : 
     558                 :             : /**
     559                 :             :  * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
     560                 :             :  *
     561                 :             :  * @param t             Current time (in frames or seconds).
     562                 :             :  * @param b             Starting value.
     563                 :             :  * @param c             Change needed in value.
     564                 :             :  * @param d             Expected easing duration (in frames or seconds).
     565                 :             :  * @param s             Overshoot amount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
     566                 :             :  * @return              The correct value.
     567                 :             :  */
     568                 :           0 : function easeOutBack(t, b, c, d, pParams) {
     569 [ #  # ][ #  # ]:           0 :     var s = !pParams || isNaN(pParams.overshoot) ? 1.70158 : pParams.overshoot;
     570                 :           0 :     return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
     571                 :             : }
     572                 :             : 
     573                 :             : /**
     574                 :             :  * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
     575                 :             :  *
     576                 :             :  * @param t             Current time (in frames or seconds).
     577                 :             :  * @param b             Starting value.
     578                 :             :  * @param c             Change needed in value.
     579                 :             :  * @param d             Expected easing duration (in frames or seconds).
     580                 :             :  * @param s             Overshoot amount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
     581                 :             :  * @return              The correct value.
     582                 :             :  */
     583                 :           0 : function easeInOutBack(t, b, c, d, pParams) {
     584 [ #  # ][ #  # ]:           0 :     var s = !pParams || isNaN(pParams.overshoot) ? 1.70158 : pParams.overshoot;
     585         [ #  # ]:           0 :     if ((t /= d / 2) < 1)
     586                 :           0 :         return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
     587                 :           0 :     return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
     588                 :             : }
     589                 :             : 
     590                 :             : /**
     591                 :             :  * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
     592                 :             :  *
     593                 :             :  * @param t             Current time (in frames or seconds).
     594                 :             :  * @param b             Starting value.
     595                 :             :  * @param c             Change needed in value.
     596                 :             :  * @param d             Expected easing duration (in frames or seconds).
     597                 :             :  * @param s             Overshoot amount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
     598                 :             :  * @return              The correct value.
     599                 :             :  */
     600                 :           0 : function easeOutInBack(t, b, c, d, pParams) {
     601         [ #  # ]:           0 :     if (t < d / 2)
     602                 :           0 :         return easeOutBack(t * 2, b, c / 2, d, pParams);
     603                 :           0 :     return easeInBack(t * 2 - d, b + c / 2, c / 2, d, pParams);
     604                 :             : }
     605                 :             : 
     606                 :             : /**
     607                 :             :  * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
     608                 :             :  *
     609                 :             :  * @param t             Current time (in frames or seconds).
     610                 :             :  * @param b             Starting value.
     611                 :             :  * @param c             Change needed in value.
     612                 :             :  * @param d             Expected easing duration (in frames or seconds).
     613                 :             :  * @return              The correct value.
     614                 :             :  */
     615                 :           0 : function easeInBounce(t, b, c, d, pParams) {
     616                 :           0 :     return c - easeOutBounce(d - t, 0, c, d) + b;
     617                 :             : }
     618                 :             : 
     619                 :             : /**
     620                 :             :  * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
     621                 :             :  *
     622                 :             :  * @param t             Current time (in frames or seconds).
     623                 :             :  * @param b             Starting value.
     624                 :             :  * @param c             Change needed in value.
     625                 :             :  * @param d             Expected easing duration (in frames or seconds).
     626                 :             :  * @return              The correct value.
     627                 :             :  */
     628                 :           0 : function easeOutBounce(t, b, c, d, pParams) {
     629         [ #  # ]:           0 :     if ((t /= d) < 1 / 2.75)
     630                 :           0 :         return c * (7.5625 * t * t) + b;
     631         [ #  # ]:           0 :     else if (t < 2 / 2.75)
     632                 :           0 :         return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
     633         [ #  # ]:           0 :     else if (t < 2.5 / 2.75)
     634                 :           0 :         return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
     635                 :             :     else
     636                 :           0 :         return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
     637                 :             : }
     638                 :             : 
     639                 :             : /**
     640                 :             :  * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
     641                 :             :  *
     642                 :             :  * @param t             Current time (in frames or seconds).
     643                 :             :  * @param b             Starting value.
     644                 :             :  * @param c             Change needed in value.
     645                 :             :  * @param d             Expected easing duration (in frames or seconds).
     646                 :             :  * @return              The correct value.
     647                 :             :  */
     648                 :           0 : function easeInOutBounce(t, b, c, d, pParams) {
     649         [ #  # ]:           0 :     if (t < d / 2)
     650                 :           0 :         return easeInBounce(t * 2, 0, c, d) * .5 + b;
     651                 :             :     else
     652                 :           0 :         return easeOutBounce(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
     653                 :             : }
     654                 :             : 
     655                 :             : /**
     656                 :             :  * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
     657                 :             :  *
     658                 :             :  * @param t             Current time (in frames or seconds).
     659                 :             :  * @param b             Starting value.
     660                 :             :  * @param c             Change needed in value.
     661                 :             :  * @param d             Expected easing duration (in frames or seconds).
     662                 :             :  * @return              The correct value.
     663                 :             :  */
     664                 :           0 : function easeOutInBounce(t, b, c, d, pParams) {
     665         [ #  # ]:           0 :     if (t < d / 2)
     666                 :           0 :         return easeOutBounce(t * 2, b, c / 2, d, pParams);
     667                 :           0 :     return easeInBounce(t * 2 - d, b + c / 2, c / 2, d, pParams);
     668                 :             : }
        

Generated by: LCOV version 2.0-1