hal_gfx_easing.h
Go to the documentation of this file.
1 
2 /** @addtogroup GRAPHICS_SDK Graphics
3  * @{
4  */
5 
6 /** @defgroup HAL_GFX_EASING Hal gfx easing
7  * @brief The interfaces of GPU easing configration.
8  * @{
9  */
10 
11 
12 #ifndef HAL_GFX_EASING_H__
13 #define HAL_GFX_EASING_H__
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 /**
20  * @defgroup HAL_GFX_EASING_FUNCTION Functions
21  * @{
22  */
23 
24 //Linear
25 // Modeled after the line y = x
26 /**
27  *****************************************************************************************
28  * @brief Linear easing, no acceleration
29  *
30  * @param[in] p: Input value, typically within the [0, 1] range
31  *
32  * @return Eased value
33  *****************************************************************************************
34  */
35 float hal_gfx_ez_linear(float p);
36 
37 //Quadratic
38 
39 // Modeled after the parabola y = x^2
40 /**
41  *****************************************************************************************
42  * @brief Quadratic easing in, accelerate from zero
43  *
44  * @param[in] p: Input value, typically within the [0, 1] range
45  *
46  * @return Eased value
47  *****************************************************************************************
48  */
49 float hal_gfx_ez_quad_in(float p);
50 
51 // Modeled after the parabola y = -x^2 + 2x
52 /**
53  *****************************************************************************************
54  * @brief Quadratic easing out, decelerate to zero velocity
55  *
56  * @param[in] p: Input value, typically within the [0, 1] range
57  *
58  * @return Eased value
59  *****************************************************************************************
60  */
61 float hal_gfx_ez_quad_out(float p);
62 
63 // Modeled after the piecewise quadratic
64 // y = (1/2)((2x)^2) ; [0, 0.5)
65 // y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
66 /**
67  *****************************************************************************************
68  * @brief Quadratic easing in and out, accelerate to halfway, then decelerate
69  *
70  * @param[in] p: Input value, typically within the [0, 1] range
71  *
72  * @return Eased value
73  *****************************************************************************************
74  */
75 float hal_gfx_ez_quad_in_out(float p);
76 
77 //Cubic
78 
79 // Modeled after the cubic y = x^3
80 /**
81  *****************************************************************************************
82  * @brief Cubic easing in, accelerate from zero
83  *
84  * @param[in] p: Input value, typically within the [0, 1] range
85  *
86  * @return Eased value
87  *****************************************************************************************
88  */
89 float hal_gfx_ez_cub_in(float p);
90 
91 // Modeled after the cubic y = (x - 1)^3 + 1
92 /**
93  *****************************************************************************************
94  * @brief Cubic easing out, decelerate to zero velocity
95  *
96  * @param[in] p: Input value, typically within the [0, 1] range
97  *
98  * @return Eased value
99  *****************************************************************************************
100  */
101 float hal_gfx_ez_cub_out(float p);
102 
103 // Modeled after the piecewise cubic
104 // y = (1/2)((2x)^3) ; [0, 0.5)
105 // y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
106 /**
107  *****************************************************************************************
108  * @brief Cubic easing in and out, accelerate to halfway, then decelerate
109  *
110  * @param[in] p: Input value, typically within the [0, 1] range
111  *
112  * @return Eased value
113  *****************************************************************************************
114  */
115 float hal_gfx_ez_cub_in_out(float p);
116 
117 //Quartic
118 
119 // Modeled after the quartic x^4
120 /**
121  *****************************************************************************************
122  * @brief Quartic easing in, accelerate from zero
123  *
124  * @param[in] p: Input value, typically within the [0, 1] range
125  *
126  * @return Eased value
127  *****************************************************************************************
128  */
129 float hal_gfx_ez_quar_in(float p);
130 
131 // Modeled after the quartic y = 1 - (x - 1)^4
132 /**
133  *****************************************************************************************
134  * @brief Quartic easing out, decelerate to zero velocity
135  *
136  * @param[in] p: Input value, typically within the [0, 1] range
137  *
138  * @return Eased value
139  *****************************************************************************************
140  */
141 float hal_gfx_ez_quar_out(float p);
142 
143 // Modeled after the piecewise quartic
144 // y = (1/2)((2x)^4) ; [0, 0.5)
145 // y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
146 /**
147  *****************************************************************************************
148  * @brief Quartic easing in and out, accelerate to halfway, then decelerate
149  *
150  * @param[in] p: Input value, typically within the [0, 1] range
151  *
152  * @return Eased value
153  *****************************************************************************************
154  */
155 float hal_gfx_ez_quar_in_out(float p);
156 
157 //Quintic
158 
159 // Modeled after the quintic y = x^5
160 /**
161  *****************************************************************************************
162  * @brief Quintic easing in, accelerate from zero
163  *
164  * @param[in] p: Input value, typically within the [0, 1] range
165  *
166  * @return Eased value
167  *****************************************************************************************
168  */
169 float hal_gfx_ez_quin_in(float p);
170 
171 // Modeled after the quintic y = (x - 1)^5 + 1
172 /**
173  *****************************************************************************************
174  * @brief Quintic easing out, decelerate to zero velocity
175  *
176  * @param[in] p: Input value, typically within the [0, 1] range
177  *
178  * @return Eased value
179  *****************************************************************************************
180  */
181 float hal_gfx_ez_quin_out(float p);
182 
183 // Modeled after the piecewise quintic
184 // y = (1/2)((2x)^5) ; [0, 0.5)
185 // y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
186 /**
187  *****************************************************************************************
188  * @brief Quintic easing in and out, accelerate to halfway, then decelerate
189  *
190  * @param[in] p: Input value, typically within the [0, 1] range
191  *
192  * @return Eased value
193  *****************************************************************************************
194  */
195 float hal_gfx_ez_quin_in_out(float p);
196 
197 //Sin
198 
199 // Modeled after quarter-cycle of sine wave
200 /**
201  *****************************************************************************************
202  * @brief Sinusoidal easing in, accelerate from zero
203  *
204  * @param[in] p: Input value, typically within the [0, 1] range
205  *
206  * @return Eased value
207  *****************************************************************************************
208  */
209 float hal_gfx_ez_sin_in(float p);
210 
211 // Modeled after quarter-cycle of sine wave (different phase)
212 /**
213  *****************************************************************************************
214  * @brief Sinusoidal easing out, decelerate to zero velocity
215  *
216  * @param[in] p: Input value, typically within the [0, 1] range
217  *
218  * @return Eased value
219  *****************************************************************************************
220  */
221 float hal_gfx_ez_sin_out(float p);
222 
223 // Modeled after half sine wave
224 /**
225  *****************************************************************************************
226  * @brief Sinusoidal easing in and out, accelerate to halfway, then decelerate
227  *
228  * @param[in] p: Input value, typically within the [0, 1] range
229  *
230  * @return Eased value
231  *****************************************************************************************
232  */
233 float hal_gfx_ez_sin_in_out(float p);
234 
235 //Circular
236 
237 // Modeled after shifted quadrant IV of unit circle
238 /**
239  *****************************************************************************************
240  * @brief Circular easing in, accelerate from zero
241  *
242  * @param[in] p: Input value, typically within the [0, 1] range
243  *
244  * @return Eased value
245  *****************************************************************************************
246  */
247 float hal_gfx_ez_circ_in(float p);
248 
249 // Modeled after shifted quadrant II of unit circle
250 /**
251  *****************************************************************************************
252  * @brief Circular easing out, decelerate to zero velocity
253  *
254  * @param[in] p: Input value, typically within the [0, 1] range
255  *
256  * @return Eased value
257  *****************************************************************************************
258  */
259 float hal_gfx_ez_circ_out(float p);
260 
261 // Modeled after the piecewise circular function
262 // y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
263 // y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
264 /**
265  *****************************************************************************************
266  * @brief Circular easing in and out, accelerate to halfway, then decelerate
267  *
268  * @param[in] p: Input value, typically within the [0, 1] range
269  *
270  * @return Eased value
271  *****************************************************************************************
272  */
273 float hal_gfx_ez_circ_in_out(float p);
274 
275 //Exponential
276 
277 // Modeled after the exponential function y = 2^(10(x - 1))
278 /**
279  *****************************************************************************************
280  * @brief Exponential easing in, accelerate from zero
281  *
282  * @param[in] p: Input value, typically within the [0, 1] range
283  *
284  * @return Eased value
285  *****************************************************************************************
286  */
287 float hal_gfx_ez_exp_in(float p);
288 
289 // Modeled after the exponential function y = -2^(-10x) + 1
290 /**
291  *****************************************************************************************
292  * @brief Exponential easing out, decelerate to zero velocity
293  *
294  * @param[in] p: Input value, typically within the [0, 1] range
295  *
296  * @return Eased value
297  *****************************************************************************************
298  */
299 float hal_gfx_ez_exp_out(float p);
300 
301 // Modeled after the piecewise exponential
302 // y = (1/2)2^(10(2x - 1)) ; [0,0.5)
303 // y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
304 /**
305  *****************************************************************************************
306  * @brief Exponential easing in and out, accelerate to halfway, then decelerate
307  *
308  * @param[in] p: Input value, typically within the [0, 1] range
309  *
310  * @return Eased value
311  *****************************************************************************************
312  */
313 float hal_gfx_ez_exp_in_out(float p);
314 
315 //Elastic
316 // Modeled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
317 
318 /**
319  *****************************************************************************************
320  * @brief Elastic easing in, accelerate from zero
321  *
322  * @param[in] p: Input value, typically within the [0, 1] range
323  *
324  * @return Eased value
325  *****************************************************************************************
326  */
327 float hal_gfx_ez_elast_in(float p);
328 
329 // Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1
330 /**
331  *****************************************************************************************
332  * @brief Elastic easing out, decelerate to zero velocity
333  *
334  * @param[in] p: Input value, typically within the [0, 1] range
335  *
336  * @return Eased value
337  *****************************************************************************************
338  */
339 float hal_gfx_ez_elast_out(float p);
340 
341 // Modeled after the piecewise exponentially-damped sine wave:
342 // y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
343 // y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
344 /**
345  *****************************************************************************************
346  * @brief Elastic easing in and out, accelerate to halfway, then decelerate
347  *
348  * @param[in] p: Input value, typically within the [0, 1] range
349  *
350  * @return Eased value
351  *****************************************************************************************
352  */
353 float hal_gfx_ez_elast_in_out(float p);
354 
355 //Back
356 
357 // Modeled after the overshooting cubic y = x^3-x*sin(x*pi)
358 /**
359  *****************************************************************************************
360  * @brief Overshooting easing in, accelerate from zero
361  *
362  * @param[in] p: Input value, typically within the [0, 1] range
363  *
364  * @return Eased value
365  *****************************************************************************************
366  */
367 float hal_gfx_ez_back_in(float p);
368 
369 // Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
370 /**
371  *****************************************************************************************
372  * @brief Overshooting easing out, decelerate to zero velocity
373  *
374  * @param[in] p: Input value, typically within the [0, 1] range
375  *
376  * @return Eased value
377  *****************************************************************************************
378  */
379 float hal_gfx_ez_back_out(float p);
380 
381 // Modeled after the piecewise overshooting cubic function:
382 // y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5)
383 // y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
384 /**
385  *****************************************************************************************
386  * @brief Overshooting easing in and out, accelerate to halfway, then decelerate
387  *
388  * @param[in] p: Input value, typically within the [0, 1] range
389  *
390  * @return Eased value
391  *****************************************************************************************
392  */
393 float hal_gfx_ez_back_in_out(float p);
394 
395 //Bounce
396 
397 /**
398  *****************************************************************************************
399  * @brief Bouncing easing in, accelerate from zero
400  *
401  * @param[in] p: Input value, typically within the [0, 1] range
402  *
403  * @return Eased value
404  *****************************************************************************************
405  */
406 float hal_gfx_ez_bounce_out(float p);
407 
408 /**
409  *****************************************************************************************
410  * @brief Bouncing easing out, decelerate to zero velocity
411  *
412  * @param[in] p: Input value, typically within the [0, 1] range
413  *
414  * @return Eased value
415  *****************************************************************************************
416  */
417 float hal_gfx_ez_bounce_in(float p);
418 
419 /**
420  *****************************************************************************************
421  * @brief Bouncing easing in and out, accelerate to halfway, then decelerate
422  *
423  * @param[in] p: Input value, typically within the [0, 1] range
424  *
425  * @return Eased value
426  *****************************************************************************************
427  */
429 
430 /**
431  *****************************************************************************************
432  * @brief Convenience function to perform easing between two values given number of steps, current step and easing function
433  *
434  * @param[in] A: Initial value within range [0, 1]
435  * @param[in] B: Finale value within range [0, 1]
436  * @param[in] steps: Total number of steps
437  * @param[in] cur_step: Current Step
438  * @param[in] ez_func: pointer to the desired easing function
439  *
440  * @return Eased value
441  *****************************************************************************************
442  */
443 float hal_gfx_ez(float A, float B, float steps, float cur_step, float (*ez_func)(float p));
444 /** @} */
445 
446 #ifdef __cplusplus
447 }
448 #endif
449 
450 #endif
451 
452 /** @} */
453 /** @} */
454 
hal_gfx_ez_exp_out
float hal_gfx_ez_exp_out(float p)
Exponential easing out, decelerate to zero velocity.
hal_gfx_ez_circ_out
float hal_gfx_ez_circ_out(float p)
Circular easing out, decelerate to zero velocity.
hal_gfx_ez_quar_in
float hal_gfx_ez_quar_in(float p)
Quartic easing in, accelerate from zero.
hal_gfx_ez_back_out
float hal_gfx_ez_back_out(float p)
Overshooting easing out, decelerate to zero velocity.
hal_gfx_ez_quin_in
float hal_gfx_ez_quin_in(float p)
Quintic easing in, accelerate from zero.
hal_gfx_ez_quar_out
float hal_gfx_ez_quar_out(float p)
Quartic easing out, decelerate to zero velocity.
hal_gfx_ez_sin_in
float hal_gfx_ez_sin_in(float p)
Sinusoidal easing in, accelerate from zero.
hal_gfx_ez_circ_in_out
float hal_gfx_ez_circ_in_out(float p)
Circular easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_cub_in
float hal_gfx_ez_cub_in(float p)
Cubic easing in, accelerate from zero.
hal_gfx_ez_quar_in_out
float hal_gfx_ez_quar_in_out(float p)
Quartic easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_sin_in_out
float hal_gfx_ez_sin_in_out(float p)
Sinusoidal easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_elast_in_out
float hal_gfx_ez_elast_in_out(float p)
Elastic easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_quad_out
float hal_gfx_ez_quad_out(float p)
Quadratic easing out, decelerate to zero velocity.
hal_gfx_ez_quin_out
float hal_gfx_ez_quin_out(float p)
Quintic easing out, decelerate to zero velocity.
hal_gfx_ez_sin_out
float hal_gfx_ez_sin_out(float p)
Sinusoidal easing out, decelerate to zero velocity.
hal_gfx_ez_linear
float hal_gfx_ez_linear(float p)
Linear easing, no acceleration.
hal_gfx_ez_bounce_out
float hal_gfx_ez_bounce_out(float p)
Bouncing easing in, accelerate from zero.
hal_gfx_ez_quad_in
float hal_gfx_ez_quad_in(float p)
Quadratic easing in, accelerate from zero.
hal_gfx_ez_circ_in
float hal_gfx_ez_circ_in(float p)
Circular easing in, accelerate from zero.
hal_gfx_ez_elast_out
float hal_gfx_ez_elast_out(float p)
Elastic easing out, decelerate to zero velocity.
hal_gfx_ez_elast_in
float hal_gfx_ez_elast_in(float p)
Elastic easing in, accelerate from zero.
hal_gfx_ez_back_in
float hal_gfx_ez_back_in(float p)
Overshooting easing in, accelerate from zero.
hal_gfx_ez_back_in_out
float hal_gfx_ez_back_in_out(float p)
Overshooting easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_cub_in_out
float hal_gfx_ez_cub_in_out(float p)
Cubic easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez
float hal_gfx_ez(float A, float B, float steps, float cur_step, float(*ez_func)(float p))
Convenience function to perform easing between two values given number of steps, current step and eas...
hal_gfx_ez_exp_in
float hal_gfx_ez_exp_in(float p)
Exponential easing in, accelerate from zero.
hal_gfx_ez_cub_out
float hal_gfx_ez_cub_out(float p)
Cubic easing out, decelerate to zero velocity.
hal_gfx_ez_exp_in_out
float hal_gfx_ez_exp_in_out(float p)
Exponential easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_bounce_in_out
float hal_gfx_ez_bounce_in_out(float p)
Bouncing easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_quin_in_out
float hal_gfx_ez_quin_in_out(float p)
Quintic easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_quad_in_out
float hal_gfx_ez_quad_in_out(float p)
Quadratic easing in and out, accelerate to halfway, then decelerate.
hal_gfx_ez_bounce_in
float hal_gfx_ez_bounce_in(float p)
Bouncing easing out, decelerate to zero velocity.