-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPennerEasing.cpp
188 lines (158 loc) · 4.97 KB
/
PennerEasing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
//
// PennerEasing.cpp
// Motions_lib_test
//
// Based on the work of Robert Penner
//
// Created by Aduen Darriba on 31/12/15.
// Copyright © 2015 Aduen Darriba. All rights reserved.
//
#define PI 3.1415926535897932384626433832795
#include "PennerEasing.h"
#include "math.h"
float Easing::Quad_easeIn(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff)
{
float c = end;
float t = t_diff;
float b = start;
float d = dur;
return c*(t/=d)*t + b;
}
float Easing::Quad_easeOut (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
return -c *(t/=d)*(t-2) + b;
}
float Easing::Quad_easeInOut (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if ((t/=d/2) < 1) return ((c/2)*(t*t)) + b;
return -c/2 * (((t-2)*(--t)) - 1) + b;
}
float Easing::Back_easeIn (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
float s = 1.70158f;
float postFix = t/=d;
return c*(postFix)*t*((s+1)*t - s) + b;
}
float Easing::Back_easeOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
float s = 1.70158f;
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
}
float Easing::Back_easeInOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
float s = 1.70158f;
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525f))+1)*t - s)) + b;
float postFix = t-=2;
return c/2*((postFix)*t*(((s*=(1.525f))+1)*t + s) + 2) + b;
}
float Easing::Bounce_easeIn (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
return c - Bounce_easeOut (d-t, 0, c, d) + b;
}
float Easing::Bounce_easeOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if ((t/=d) < (1/2.75f)) {
return c*(7.5625f*t*t) + b;
} else if (t < (2/2.75f)) {
float postFix = t-=(1.5f/2.75f);
return c*(7.5625f*(postFix)*t + .75f) + b;
} else if (t < (2.5/2.75)) {
float postFix = t-=(2.25f/2.75f);
return c*(7.5625f*(postFix)*t + .9375f) + b;
} else {
float postFix = t-=(2.625f/2.75f);
return c*(7.5625f*(postFix)*t + .984375f) + b;
}
}
float Easing::Bounce_easeInOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if (t < d/2) return Bounce_easeIn (t*2, 0, c, d) * .5f + b;
else return Bounce_easeOut (t*2-d, 0, c, d) * .5f + c*.5f + b;
}
float Easing::Expo_easeIn (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
return (t==0) ? b : c * pow(2, 10 * (t/d - 1)) + b;
}
float Easing::Expo_easeOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
return (t==d) ? b+c : c * (-pow(2, -10 * t/d) + 1) + b;
}
float Easing::Expo_easeInOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if (t==0) return b;
if (t==d) return b+c;
if ((t/=d/2) < 1) return c/2 * pow(2, 10 * (t - 1)) + b;
return c/2 * (-pow(2, -10 * --t) + 2) + b;
}
float Easing::Elastic_easeIn (uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if (t==0) return b; if ((t/=d)==1) return b+c;
float p=d*.3f;
float a=c;
float s=p/4;
float postFix =a*pow(2,10*(t-=1));
return -(postFix * sin((t*d-s)*(2*PI)/p )) + b;
}
float Easing::Elastic_easeOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if (t==0) return b; if ((t/=d)==1) return b+c;
float p=d*.3f;
float a=c;
float s=p/4;
return (a*pow(2,-10*t) * sin( (t*d-s)*(2*PI)/p ) + c + b);
}
float Easing::Elastic_easeInOut(uint16_t start, uint16_t end, uint32_t dur, uint32_t t_diff) {
float c = end;
float t = t_diff;
float b = start;
float d = dur;
if (t==0) return b; if ((t/=d/2)==2) return b+c;
float p=d*(.3f*1.5f);
float a=c;
float s=p/4;
if (t < 1) {
float postFix =a*pow(2,10*(t-=1));
return -.5f*(postFix* sin( (t*d-s)*(2*PI)/p )) + b;
}
float postFix = a*pow(2,-10*(t-=1));
return postFix * sin( (t*d-s)*(2*PI)/p )*.5f + c + b;
}