NasNas
An intuitive and beginner friendly 2D game framework for C++
Easing.hpp
1 // Created by Modar Nasser on 18/07/2021.
2 
3 #pragma once
4 
5 #include <array>
6 #include <functional>
7 
8 namespace ns {
9 
10  namespace tween {
11  using EasingFunction = std::function<float(float)>;
12  using CallbackFunction = std::function<void(float)>;
13 
14  template <unsigned N>
15  using MultiCallbackFunction = std::function<void(std::array<float, N>)>;
16  }
17 
18  struct easing {
19  static auto linear(float t) -> float;
20 
21  static auto quadraticIn(float t) -> float;
22  static auto quadraticOut(float t) -> float;
23  static auto quadraticInOut(float t) -> float;
24 
25  static auto cubicIn(float t) -> float;
26  static auto cubicOut(float t) -> float;
27  static auto cubicInOut(float t) -> float;
28 
29  static auto sinusoidalIn(float t) -> float;
30  static auto sinusoidalOut(float t) -> float;
31  static auto sinusoidalInOut(float t) -> float;
32 
33  static auto exponentialIn(float t) -> float;
34  static auto exponentialOut(float t) -> float;
35  static auto exponentialInOut(float t) -> float;
36 
37  static auto circularIn(float t) -> float;
38  static auto circularOut(float t) -> float;
39  static auto circularInOut(float t) -> float;
40 
41  static auto bounceIn(float t) -> float;
42  static auto bounceOut(float t) -> float;
43  static auto bounceInOut(float t) -> float;
44 
45  static auto backIn(float t) -> float;
46  static auto backOut(float t) -> float;
47  static auto backInOut(float t) -> float;
48 
49  static auto backIn2(float t) -> float;
50  static auto backOut2(float t) -> float;
51  static auto backInOut2(float t) -> float;
52 
53  static auto elasticIn(float t) -> float;
54  static auto elasticOut(float t) -> float;
55  static auto elasticInOut(float t) -> float;
56 
57  struct custom {
58  template <unsigned Degree> static auto polynomialIn(float t) -> float;
59  template <unsigned Degree> static auto polynomialOut(float t) -> float;
60  template <unsigned Degree> static auto polynomialInOut(float t) -> float;
61 
62  template <unsigned Pull> static auto backIn(float t) -> float;
63  template <unsigned Pull> static auto backOut(float t) -> float;
64  template <unsigned Pull> static auto backInOut(float t) -> float;
65 
66  template <unsigned Pull> static auto backIn2(float t) -> float;
67  template <unsigned Pull> static auto backOut2(float t) -> float;
68  template <unsigned Pull> static auto backInOut2(float t) -> float;
69 
70  template <unsigned Ondulation> static auto elasticIn(float t) -> float;
71  template <unsigned Ondulation> static auto elasticOut(float t) -> float;
72  template <unsigned Ondulation> static auto elasticInOut(float t) -> float;
73  };
74  };
75 }
76 
77 #include "NasNas/tween/Easing.tpp"