File size: 5,496 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
//! Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your own !!)
class Easing
{
	static float EaseInSine( float t ) 
	{
		return -1 * Math.Cos( t * ( Math.PI / 2 ) ) + 1;
	}

	static float EaseOutSine( float t ) 
	{
		return Math.Sin( t * ( Math.PI / 2 ) );
	}

	static float EaseInOutSine( float t ) 
	{
		return -0.5 * ( Math.Cos( Math.PI * t ) - 1 );
	}

	static float EaseInQuad( float t ) 
	{
		return t * t;
	}

	static float EaseOutQuad( float t ) 
	{
		return t * ( 2 - t );
	}

	static float EaseInOutQuad( float t ) 
	{
		if(t < 0.5)
			return 2 * t * t;
		else 
			return -1 + ( 4 - 2 * t ) * t;
	}

	static float EaseInCubic( float t ) 
	{
		return t * t * t;
	}

	static float EaseOutCubic( float t ) 
	{
		float t1 = t - 1;
		return t1 * t1 * t1 + 1;
	}

	static float EaseInOutCubic( float t ) 
	{
		if( t < 0.5 ) 
			return 4 * t * t * t;
		else 
			return ( t - 1 ) * ( 2 * t - 2 ) * ( 2 * t - 2 ) + 1;
	}

	static float EaseInQuart( float t ) 
	{
		return t * t * t * t;
	}

	static float EaseOutQuart( float t ) 
	{
		float t1 = t - 1;
		return 1 - t1 * t1 * t1 * t1;
	}


	static float EaseInOutQuart( float t ) 
	{
		float t1 = t - 1;
		
		if(t < 0.5)
			return 8 * t * t * t * t;
		else
			return 1 - 8 * t1 * t1 * t1 * t1;
	}

	static float EaseInQuint( float t ) 
	{
		return t * t * t * t * t;
	}

	static float EaseOutQuint( float t ) 
	{
		float t1 = t - 1;
		return 1 + t1 * t1 * t1 * t1 * t1;
	}

	static float EaseInOutQuint( float t ) 
	{
		float t1 = t - 1;
		
		if( t < 0.5 )
		{
			return 16 * t * t * t * t * t;
		}
		else
		{
			return  1 + 16 * t1 * t1 * t1 * t1 * t1;
		}
	}

	static float EaseInExpo( float t ) 
	{
		if( t == 0 ) 
		{
			return 0;
		}
		
		return 	Math.Pow( 2, 10 * ( t - 1 ) );
	}

	static float EaseOutExpo( float t ) 
	{
		if( t == 1 ) {
			return 1;
		}

		return ( -Math.Pow( 2, -10 * t ) + 1 );
	}

	static float EaseInOutExpo( float t ) 
	{
    
		if( t == 0 || t == 1 ) 
		{
			return t;
    	}

	    float scaledTime = t * 2;
	    float scaledTime1 = scaledTime - 1;
			
	    if( scaledTime < 1 ) 
		{
	       return 0.5 * Math.Pow( 2, 10 *  scaledTime1 );
	   	}
	
		return 0.5 * ( -Math.Pow( 2, -10 * scaledTime1 ) + 2 );

	}

	static float EaseInCirc( float t ) 
	{
		float scaledTime = t / 1;
		return -1 * ( Math.Sqrt( 1 - scaledTime * t ) - 1 );
	}

	static float EaseOutCirc( float t ) 
	{
		float t1 = t - 1;
		return Math.Sqrt( 1 - t1 * t1 );
	}
	
	static float EaseInOutCirc( float t ) 
	{

		float scaledTime = t * 2;
		float scaledTime1 = scaledTime - 2;

		if( scaledTime < 1 ) 
		{
			return -0.5 * ( Math.Sqrt( 1 - scaledTime * scaledTime ) - 1 );
		}

		return 0.5 * ( Math.Sqrt( 1 - scaledTime1 * scaledTime1 ) + 1 );
	}

	static float EaseInBack( float t, float magnitude = 1.70158 ) 
	{
		return t * t * ( ( magnitude + 1 ) * t - magnitude );
	}

	static float EaseOutBack( float t, float magnitude = 1.70158 ) 
	{
		float scaledTime = ( t / 1 ) - 1;
		return (scaledTime * scaledTime * ( ( magnitude + 1 ) * scaledTime + magnitude )) + 1;
	}

	static float EaseInOutBack( float t, float magnitude = 1.70158 ) 
	{

		float scaledTime = t * 2;
		float scaledTime2 = scaledTime - 2;

		float s = magnitude * 1.525;

		if( scaledTime < 1) 
		{
			return 0.5 * scaledTime * scaledTime * (( ( s + 1 ) * scaledTime ) - s);
		}

		return 0.5 * (scaledTime2 * scaledTime2 * ( ( s + 1 ) * scaledTime2 + s ) + 2);
	}

	static float EaseInElastic( float t, float magnitude = 0.7 ) 
	{
		if( t == 0 || t == 1 ) 
			return t;

		float scaledTime = t / 1;
		float scaledTime1 = scaledTime - 1;

		float p = 1 - magnitude;
		float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );

		return -(Math.Pow( 2, 10 * scaledTime1 ) * Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ));
	}

	static float EaseOutElastic( float t, float magnitude = 0.7 ) 
	{
		float p = 1 - magnitude;
		float scaledTime = t * 2;

		if( t == 0 || t == 1 ) {
			return t;
		}

		float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );
		return (Math.Pow( 2, -10 * scaledTime ) * Math.Sin( ( scaledTime - s ) * ( 2 * Math.PI ) / p )) + 1;
	}

	static float EaseInOutElastic( float t, float magnitude = 0.65 ) 
	{
		float p = 1 - magnitude;

		if( t == 0 || t == 1 ) 
		{
			return t;
		}

		float scaledTime = t * 2;
		float scaledTime1 = scaledTime - 1;
		
		float s = p / ( 2 * Math.PI ) * Math.Asin( 1 );

		if( scaledTime < 1 ) 
		{
			return -0.5 * (Math.Pow( 2, 10 * scaledTime1 ) * Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ));
		}

		return (Math.Pow( 2, -10 * scaledTime1 ) *        Math.Sin( ( scaledTime1 - s ) * ( 2 * Math.PI ) / p ) * 0.5) + 1;
	}

	static float EaseOutBounce( float t ) 
	{

		float scaledTime = t / 1;

		if( scaledTime < ( 1 / 2.75 ) ) {

			return 7.5625 * scaledTime * scaledTime;

		} else if( scaledTime < ( 2 / 2.75 ) ) {

			float scaledTime2 = scaledTime - ( 1.5 / 2.75 );
			return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.75;

		} else if( scaledTime < ( 2.5 / 2.75 ) ) {

			scaledTime2 = scaledTime - ( 2.25 / 2.75 );
			return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.9375;

		} else {

			scaledTime2 = scaledTime - ( 2.625 / 2.75 );
			return ( 7.5625 * scaledTime2 * scaledTime2 ) + 0.984375;

		}
	}

	static float EaseInBounce( float t ) 
	{
		return 1 - EaseOutBounce( 1 - t );
	}

	static float EaseInOutBounce( float t ) 
	{
		if( t < 0.5 ) 
		{
			return EaseInBounce( t * 2 ) * 0.5;
		}
		return ( EaseOutBounce( ( t * 2 ) - 1 ) * 0.5 ) + 0.5;
	}
}