hal_gfx_easing.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_gfx_easing.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of Graphics library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  specific prior written permission.
23 
24  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup GRAPHICS_SDK Graphics
39  * @{
40  */
41 
42 /** @addtogroup HAL_GFX HAL GFX
43  * @{
44  */
45 
46 /** @defgroup HAL_GFX_EASING GFX EASING
47  * @brief The interfaces of GPU easing configration.
48  * @{
49  */
50 
51 
52 #ifndef HAL_GFX_EASING_H__
53 #define HAL_GFX_EASING_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /**
60  * @defgroup HAL_GFX_EASING_FUNCTION Functions
61  * @{
62  */
63 
64 //Linear
65 // Modeled after the line y = x
66 /**
67  *****************************************************************************************
68  * @brief Linear easing, no acceleration
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_linear(float p);
76 
77 //Quadratic
78 
79 // Modeled after the parabola y = x^2
80 /**
81  *****************************************************************************************
82  * @brief Quadratic 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_quad_in(float p);
90 
91 // Modeled after the parabola y = -x^2 + 2x
92 /**
93  *****************************************************************************************
94  * @brief Quadratic 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_quad_out(float p);
102 
103 // Modeled after the piecewise quadratic
104 // y = (1/2)((2x)^2) ; [0, 0.5)
105 // y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
106 /**
107  *****************************************************************************************
108  * @brief Quadratic 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_quad_in_out(float p);
116 
117 //Cubic
118 
119 // Modeled after the cubic y = x^3
120 /**
121  *****************************************************************************************
122  * @brief Cubic 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_cub_in(float p);
130 
131 // Modeled after the cubic y = (x - 1)^3 + 1
132 /**
133  *****************************************************************************************
134  * @brief Cubic 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_cub_out(float p);
142 
143 // Modeled after the piecewise cubic
144 // y = (1/2)((2x)^3) ; [0, 0.5)
145 // y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
146 /**
147  *****************************************************************************************
148  * @brief Cubic 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_cub_in_out(float p);
156 
157 //Quartic
158 
159 // Modeled after the quartic x^4
160 /**
161  *****************************************************************************************
162  * @brief Quartic 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_quar_in(float p);
170 
171 // Modeled after the quartic y = 1 - (x - 1)^4
172 /**
173  *****************************************************************************************
174  * @brief Quartic 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_quar_out(float p);
182 
183 // Modeled after the piecewise quartic
184 // y = (1/2)((2x)^4) ; [0, 0.5)
185 // y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
186 /**
187  *****************************************************************************************
188  * @brief Quartic 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_quar_in_out(float p);
196 
197 //Quintic
198 
199 // Modeled after the quintic y = x^5
200 /**
201  *****************************************************************************************
202  * @brief Quintic 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_quin_in(float p);
210 
211 // Modeled after the quintic y = (x - 1)^5 + 1
212 /**
213  *****************************************************************************************
214  * @brief Quintic 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_quin_out(float p);
222 
223 // Modeled after the piecewise quintic
224 // y = (1/2)((2x)^5) ; [0, 0.5)
225 // y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
226 /**
227  *****************************************************************************************
228  * @brief Quintic easing in and out, accelerate to halfway, then decelerate
229  *
230  * @param[in] p: Input value, typically within the [0, 1] range
231  *
232  * @return Eased value
233  *****************************************************************************************
234  */
235 float hal_gfx_ez_quin_in_out(float p);
236 
237 //Sin
238 
239 // Modeled after quarter-cycle of sine wave
240 /**
241  *****************************************************************************************
242  * @brief Sinusoidal easing in, accelerate from zero
243  *
244  * @param[in] p: Input value, typically within the [0, 1] range
245  *
246  * @return Eased value
247  *****************************************************************************************
248  */
249 float hal_gfx_ez_sin_in(float p);
250 
251 // Modeled after quarter-cycle of sine wave (different phase)
252 /**
253  *****************************************************************************************
254  * @brief Sinusoidal easing out, decelerate to zero velocity
255  *
256  * @param[in] p: Input value, typically within the [0, 1] range
257  *
258  * @return Eased value
259  *****************************************************************************************
260  */
261 float hal_gfx_ez_sin_out(float p);
262 
263 // Modeled after half sine wave
264 /**
265  *****************************************************************************************
266  * @brief Sinusoidal 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_sin_in_out(float p);
274 
275 //Circular
276 
277 // Modeled after shifted quadrant IV of unit circle
278 /**
279  *****************************************************************************************
280  * @brief Circular 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_circ_in(float p);
288 
289 // Modeled after shifted quadrant II of unit circle
290 /**
291  *****************************************************************************************
292  * @brief Circular 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_circ_out(float p);
300 
301 // Modeled after the piecewise circular function
302 // y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
303 // y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
304 /**
305  *****************************************************************************************
306  * @brief Circular 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_circ_in_out(float p);
314 
315 //Exponential
316 
317 // Modeled after the exponential function y = 2^(10(x - 1))
318 /**
319  *****************************************************************************************
320  * @brief Exponential 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_exp_in(float p);
328 
329 // Modeled after the exponential function y = -2^(-10x) + 1
330 /**
331  *****************************************************************************************
332  * @brief Exponential 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_exp_out(float p);
340 
341 // Modeled after the piecewise exponential
342 // y = (1/2)2^(10(2x - 1)) ; [0,0.5)
343 // y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
344 /**
345  *****************************************************************************************
346  * @brief Exponential 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_exp_in_out(float p);
354 
355 //Elastic
356 // Modeled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
357 
358 /**
359  *****************************************************************************************
360  * @brief Elastic 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_elast_in(float p);
368 
369 // Modeled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1
370 /**
371  *****************************************************************************************
372  * @brief Elastic 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_elast_out(float p);
380 
381 // Modeled after the piecewise exponentially-damped sine wave:
382 // y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
383 // y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
384 /**
385  *****************************************************************************************
386  * @brief Elastic 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_elast_in_out(float p);
394 
395 //Back
396 
397 // Modeled after the overshooting cubic y = x^3-x*sin(x*pi)
398 /**
399  *****************************************************************************************
400  * @brief Overshooting easing in, accelerate from zero
401  *
402  * @param[in] p: Input value, typically within the [0, 1] range
403  *
404  * @return Eased value
405  *****************************************************************************************
406  */
407 float hal_gfx_ez_back_in(float p);
408 
409 // Modeled after overshooting cubic y = 1-((1-x)^3-(1-x)*sin((1-x)*pi))
410 /**
411  *****************************************************************************************
412  * @brief Overshooting easing out, decelerate to zero velocity
413  *
414  * @param[in] p: Input value, typically within the [0, 1] range
415  *
416  * @return Eased value
417  *****************************************************************************************
418  */
419 float hal_gfx_ez_back_out(float p);
420 
421 // Modeled after the piecewise overshooting cubic function:
422 // y = (1/2)*((2x)^3-(2x)*sin(2*x*pi)) ; [0, 0.5)
423 // y = (1/2)*(1-((1-x)^3-(1-x)*sin((1-x)*pi))+1) ; [0.5, 1]
424 /**
425  *****************************************************************************************
426  * @brief Overshooting easing in and out, accelerate to halfway, then decelerate
427  *
428  * @param[in] p: Input value, typically within the [0, 1] range
429  *
430  * @return Eased value
431  *****************************************************************************************
432  */
433 float hal_gfx_ez_back_in_out(float p);
434 
435 //Bounce
436 
437 /**
438  *****************************************************************************************
439  * @brief Bouncing easing in, accelerate from zero
440  *
441  * @param[in] p: Input value, typically within the [0, 1] range
442  *
443  * @return Eased value
444  *****************************************************************************************
445  */
446 float hal_gfx_ez_bounce_out(float p);
447 
448 /**
449  *****************************************************************************************
450  * @brief Bouncing easing out, decelerate to zero velocity
451  *
452  * @param[in] p: Input value, typically within the [0, 1] range
453  *
454  * @return Eased value
455  *****************************************************************************************
456  */
457 float hal_gfx_ez_bounce_in(float p);
458 
459 /**
460  *****************************************************************************************
461  * @brief Bouncing easing in and out, accelerate to halfway, then decelerate
462  *
463  * @param[in] p: Input value, typically within the [0, 1] range
464  *
465  * @return Eased value
466  *****************************************************************************************
467  */
469 
470 /**
471  *****************************************************************************************
472  * @brief Convenience function to perform easing between two values given number of steps, current step and easing function
473  *
474  * @param[in] A: Initial value within range [0, 1]
475  * @param[in] B: Finale value within range [0, 1]
476  * @param[in] steps: Total number of steps
477  * @param[in] cur_step: Current Step
478  * @param[in] ez_func: pointer to the desired easing function
479  *
480  * @return Eased value
481  *****************************************************************************************
482  */
483 float hal_gfx_ez(float A, float B, float steps, float cur_step, float (*ez_func)(float p));
484 /** @} */
485 
486 #ifdef __cplusplus
487 }
488 #endif
489 
490 #endif
491 
492 /** @} */
493 /** @} */
494 /** @} */
495 
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.