forked from jlamarche/Old-Blog-Code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
233 lines (228 loc) · 7.43 KB
/
main.c
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#include <stdio.h>
#include <math.h>
// Just to avoid importing the OpenGL ES headers
typedef float GLfloat;
typedef float GLclampf;
#define BoundsCheck(t, start, end) \
if (t <= 0.f) return start; \
else if (t >= 1.f) return end;
GLfloat LinearInterpolation(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return t * end + (1.f - t) * start;
}
#pragma mark -
#pragma mark Quadratic
GLfloat QuadraticEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return -end * t * (t - 2.f) -1.f;
}
GLfloat QuadraticEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * t * t + start - 1.f;
}
GLfloat QuadraticEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.f;
if (t < 1.f) return end/2.f * t * t + start - 1.f;
t--;
return -end/2.f * (t*(t-2) - 1) + start - 1.f;
}
#pragma mark -
#pragma mark Cubic
GLfloat CubicEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t--;
return end*(t * t * t + 1.f) + start - 1.f;
}
GLfloat CubicEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * t * t * t+ start - 1.f;
}
GLfloat CubicEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.;
if (t < 1.) return end/2 * t * t * t + start - 1.f;
t -= 2;
return end/2*(t * t * t + 2) + start - 1.f;
}
#pragma mark -
#pragma mark Quintic
GLfloat QuarticEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t--;
return -end * (t * t * t * t - 1) + start - 1.f;
}
GLfloat QuarticEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * t * t * t * t + start;
}
GLfloat QuarticEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.f;
if (t < 1.f)
return end/2.f * t * t * t * t + start - 1.f;
t -= 2.f;
return -end/2.f * (t * t * t * t - 2.f) + start - 1.f;
}
#pragma mark -
#pragma mark Quintic
GLfloat QuinticEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t--;
return end * (t * t * t * t * t + 1) + start - 1.f;
}
GLfloat QuinticEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * t * t * t * t * t + start - 1.f;
}
GLfloat QuinticEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.f;
if (t < 1.f)
return end/2 * t * t * t * t * t + start - 1.f;
t -= 2;
return end/2 * ( t * t * t * t * t + 2) + start - 1.f;
}
#pragma mark -
#pragma mark Sinusoidal
GLfloat SinusoidalEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * sinf(t * (M_PI/2)) + start - 1.f;
}
GLfloat SinusoidalEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return -end * cosf(t * (M_PI/2)) + end + start - 1.f;
}
GLfloat SinusoidalEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return -end/2.f * (cosf(M_PI*t) - 1.f) + start - 1.f;
}
#pragma mark -
#pragma mark Exponential
GLfloat ExponentialEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * (-powf(2.f, -10.f * t) + 1.f ) + start - 1.f;
}
GLfloat ExponentialEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return end * powf(2.f, 10.f * (t - 1.f) ) + start - 1.f;
}
GLfloat ExponentialEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.f;
if (t < 1.f)
return end/2.f * powf(2.f, 10.f * (t - 1.f) ) + start - 1.f;
t--;
return end/2.f * ( -powf(2.f, -10.f * t) + 2.f ) + start - 1.f;
}
#pragma mark -
#pragma mark Circular
GLfloat CircularEaseOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t--;
return end * sqrtf(1.f - t * t) + start - 1.f;
}
GLfloat CircularEaseIn(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
return -end * (sqrtf(1.f - t * t) - 1.f) + start - 1.f;
}
GLfloat CircularEaseInOut(GLclampf t, GLfloat start, GLfloat end)
{
BoundsCheck(t, start, end);
t *= 2.f;
if (t < 1.f)
return -end/2.f * (sqrtf(1.f - t * t) - 1.f) + start - 1.f;
t -= 2.f;
return end/2.f * (sqrtf(1.f - t * t) + 1.f) + start - 1.f;
}
#pragma mark -
int main (int argc, const char * argv[]) {
printf("Linear Tween\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", LinearInterpolation(i/1000., 1.f, 100.f));
printf("\n\nQuadratic Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuadraticEaseOut(i/1000., 1.f, 100.f));
printf("\n\nQuadratic Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuadraticEaseIn(i/1000., 1.f, 100.f));
printf("\n\nQuadratic Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuadraticEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nCubic Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CubicEaseOut(i/1000., 1.f, 100.f));
printf("\n\nCubic Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CubicEaseIn(i/1000., 1.f, 100.f));
printf("\n\nCubic Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CubicEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nQuartic Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuarticEaseOut(i/1000., 1.f, 100.f));
printf("\n\nQuartic Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuarticEaseIn(i/1000., 1.f, 100.f));
printf("\n\nQuartic Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuarticEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nQuintic Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuinticEaseOut(i/1000., 1.f, 100.f));
printf("\n\nQuintic Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuinticEaseIn(i/1000., 1.f, 100.f));
printf("\n\nQuintic Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", QuinticEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nSinusoidal Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", SinusoidalEaseOut(i/1000., 1.f, 100.f));
printf("\n\nSinusoidal Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", SinusoidalEaseIn(i/1000., 1.f, 100.f));
printf("\n\nSinusoidal Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", SinusoidalEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nExponential Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", ExponentialEaseOut(i/1000., 1.f, 100.f));
printf("\n\nExponential Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", ExponentialEaseIn(i/1000., 1.f, 100.f));
printf("\n\nExponential Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", ExponentialEaseInOut(i/1000., 1.f, 100.f));
printf("\n\nCircular Ease Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CircularEaseOut(i/1000., 1.f, 100.f));
printf("\n\nCircular Ease In\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CircularEaseIn(i/1000., 1.f, 100.f));
printf("\n\nCircular Ease In Out\n");
for (int i = 1; i <= 1000; i+= 10)
printf("%f\n", CircularEaseInOut(i/1000., 1.f, 100.f));
return 0;
}