@@ -6,44 +6,67 @@ namespace Windows.UI.Xaml.Media.Animation
6
6
{
7
7
public partial class BounceEase : EasingFunctionBase
8
8
{
9
+ // Source: https://easings.net/
10
+
9
11
public override double Ease ( double currentTime , double startValue , double finalValue , double duration )
10
12
{
11
- //Depending on the mode we have different functions for the return value.
12
- switch ( this . EasingMode )
13
+ var delta = finalValue - startValue ;
14
+ var progress = currentTime / duration ;
15
+
16
+ var ratio = EaseCore ( progress ) ;
17
+
18
+ return startValue + ratio * delta ;
19
+ }
20
+
21
+ internal double EaseCore ( double progress )
22
+ {
23
+ switch ( EasingMode )
13
24
{
14
25
case EasingMode . EaseIn :
15
- return BounceEaseIn ( currentTime , startValue , finalValue , duration ) ;
26
+ return BounceEaseIn ( progress ) ;
16
27
17
28
case EasingMode . EaseOut :
18
- return BounceEaseOut ( currentTime , startValue , finalValue , duration ) ;
29
+ return BounceEaseOut ( progress ) ;
19
30
20
31
case EasingMode . EaseInOut :
21
-
22
- if ( currentTime < duration / 2 )
23
- return BounceEaseIn ( currentTime * 2 , 0 , finalValue , duration ) * .5 + startValue ;
24
- else
25
- return BounceEaseOut ( currentTime * 2 - duration , 0 , finalValue , duration ) * .5 + finalValue * .5 + startValue ;
26
-
27
32
default :
28
- return finalValue * currentTime / duration + startValue ;
33
+ return BounceEaseInOut ( progress ) ;
29
34
}
30
35
}
31
36
32
- public static double BounceEaseIn ( double currentTime , double startValue , double finalValue , double duration )
37
+ public static double BounceEaseIn ( double progress )
33
38
{
34
- return finalValue - BounceEaseOut ( duration - currentTime , 0 , finalValue , duration ) + startValue ;
39
+ return 1 - BounceEaseOut ( 1 - progress ) ;
35
40
}
36
41
37
- public static double BounceEaseOut ( double currentTime , double startValue , double finalValue , double duration )
42
+ public static double BounceEaseOut ( double progress )
38
43
{
39
- if ( ( currentTime /= duration ) < ( 1 / 2.75 ) )
40
- return finalValue * ( 7.5625 * currentTime * currentTime ) + startValue ;
41
- else if ( currentTime < ( 2 / 2.75 ) )
42
- return finalValue * ( 7.5625 * ( currentTime -= ( 1.5 / 2.75 ) ) * currentTime + .75 ) + startValue ;
43
- else if ( currentTime < ( 2.5 / 2.75 ) )
44
- return finalValue * ( 7.5625 * ( currentTime -= ( 2.25 / 2.75 ) ) * currentTime + .9375 ) + startValue ;
44
+ const double n1 = 7.5625 ;
45
+ const double d1 = 2.75 ;
46
+
47
+ if ( progress < 1 / d1 )
48
+ {
49
+ return n1 * progress * progress ;
50
+ }
51
+ else if ( progress < 2 / d1 )
52
+ {
53
+ return n1 * ( progress -= 1.5 / d1 ) * progress + 0.75 ;
54
+ }
55
+ else if ( progress < 2.5 / d1 )
56
+ {
57
+ return n1 * ( progress -= 2.25 / d1 ) * progress + 0.9375 ;
58
+ }
45
59
else
46
- return finalValue * ( 7.5625 * ( currentTime -= ( 2.625 / 2.75 ) ) * currentTime + .984375 ) + startValue ;
60
+ {
61
+ return n1 * ( progress -= 2.625 / d1 ) * progress + 0.984375 ;
62
+ }
47
63
}
48
- }
64
+
65
+ public static double BounceEaseInOut ( double progress )
66
+ {
67
+ return progress < 0.5
68
+ ? ( 1 - BounceEaseOut ( 1 - 2 * progress ) ) / 2
69
+ : ( 1 + BounceEaseOut ( 2 * progress - 1 ) ) / 2 ;
70
+ }
71
+ }
49
72
}
0 commit comments