Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoEase.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoEase provides animation curve equations for animation support.
3 
4 Written by Michael C. Miller.
5 
6 I invest time and resources providing this open source code,
7 please support me by dontating (see https://github.com/Makuna)
8 
9 -------------------------------------------------------------------------
10 This file is part of the LUMITRONIX_iFlex_Workshop library.
11 
12 LumitronixIFlexBus is free software: you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as
14 published by the Free Software Foundation, either version 3 of
15 the License, or (at your option) any later version.
16 
17 LumitronixIFlexBus is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU Lesser General Public License for more details.
21 
22 You should have received a copy of the GNU Lesser General Public
23 License along with LumitronixIFlex. If not, see
24 <http://www.gnu.org/licenses/>.
25 -------------------------------------------------------------------------*/
26 
27 #pragma once
28 
29 #if defined(NEOPIXEBUS_NO_STL)
30 
31 typedef float(*AnimEaseFunction)(float unitValue);
32 
33 #else
34 
35 #undef max
36 #undef min
37 #include <functional>
38 typedef std::function<float(float unitValue)> AnimEaseFunction;
39 
40 #endif
41 
42 class NeoEase
43 {
44 public:
45  static float Linear(float unitValue)
46  {
47  return unitValue;
48  }
49 
50  static float QuadraticIn(float unitValue)
51  {
52  return unitValue * unitValue;
53  }
54 
55  static float QuadraticOut(float unitValue)
56  {
57  return (-unitValue * (unitValue - 2.0f));
58  }
59 
60  static float QuadraticInOut(float unitValue)
61  {
62  unitValue *= 2.0f;
63  if (unitValue < 1.0f)
64  {
65  return (0.5f * unitValue * unitValue);
66  }
67  else
68  {
69  unitValue -= 1.0f;
70  return (-0.5f * (unitValue * (unitValue - 2.0f) - 1.0f));
71  }
72  }
73 
74  static float QuadraticCenter(float unitValue)
75  {
76  unitValue *= 2.0f;
77  if (unitValue < 1.0f)
78  {
79  return (-0.5f * (unitValue * unitValue - 2.0f));
80  }
81  else
82  {
83  unitValue -= 1.0f;
84  return (0.5f * (unitValue * unitValue + 1.0f));
85  }
86  }
87 
88  static float CubicIn(float unitValue)
89  {
90  return (unitValue * unitValue * unitValue);
91  }
92 
93  static float CubicOut(float unitValue)
94  {
95  unitValue -= 1.0f;
96  return (unitValue * unitValue * unitValue + 1.0f);
97  }
98 
99  static float CubicInOut(float unitValue)
100  {
101  unitValue *= 2.0f;
102  if (unitValue < 1.0f)
103  {
104  return (0.5f * unitValue * unitValue * unitValue);
105  }
106  else
107  {
108  unitValue -= 2.0f;
109  return (0.5f * (unitValue * unitValue * unitValue + 2.0f));
110  }
111  }
112 
113  static float CubicCenter(float unitValue)
114  {
115  unitValue *= 2.0f;
116  unitValue -= 1.0f;
117  return (0.5f * (unitValue * unitValue * unitValue + 1.0f));
118  }
119 
120  static float QuarticIn(float unitValue)
121  {
122  return (unitValue * unitValue * unitValue * unitValue);
123  }
124 
125  static float QuarticOut(float unitValue)
126  {
127  unitValue -= 1.0f;
128  return -(unitValue * unitValue * unitValue * unitValue - 1.0f);
129  }
130 
131  static float QuarticInOut(float unitValue)
132  {
133  unitValue *= 2.0f;
134  if (unitValue < 1.0f)
135  {
136  return (0.5f * unitValue * unitValue * unitValue * unitValue);
137  }
138  else
139  {
140  unitValue -= 2.0f;
141  return (-0.5f * (unitValue * unitValue * unitValue * unitValue - 2.0f));
142  }
143  }
144 
145  static float QuarticCenter(float unitValue)
146  {
147  unitValue *= 2.0f;
148  unitValue -= 1.0f;
149  if (unitValue < 0.0f)
150  {
151  return (-0.5f * (unitValue * unitValue * unitValue * unitValue - 1.0f));
152  }
153  else
154  {
155  return (0.5f * (unitValue * unitValue * unitValue * unitValue + 1.0f));
156  }
157  }
158 
159  static float QuinticIn(float unitValue)
160  {
161  return (unitValue * unitValue * unitValue * unitValue * unitValue);
162  }
163 
164  static float QuinticOut(float unitValue)
165  {
166  unitValue -= 1.0f;
167  return (unitValue * unitValue * unitValue * unitValue * unitValue + 1.0f);
168  }
169 
170  static float QuinticInOut(float unitValue)
171  {
172  unitValue *= 2.0f;
173  if (unitValue < 1.0f)
174  {
175  return (0.5f * unitValue * unitValue * unitValue * unitValue * unitValue);
176  }
177  else
178  {
179  unitValue -= 2.0f;
180  return (0.5f * (unitValue * unitValue * unitValue * unitValue * unitValue + 2.0f));
181  }
182  }
183 
184  static float QuinticCenter(float unitValue)
185  {
186  unitValue *= 2.0f;
187  unitValue -= 1.0f;
188  return (0.5f * (unitValue * unitValue * unitValue * unitValue * unitValue + 1.0f));
189  }
190 
191  static float SinusoidalIn(float unitValue)
192  {
193  return (-cos(unitValue * HALF_PI) + 1.0f);
194  }
195 
196  static float SinusoidalOut(float unitValue)
197  {
198  return (sin(unitValue * HALF_PI));
199  }
200 
201  static float SinusoidalInOut(float unitValue)
202  {
203  return -0.5f * (cos(PI * unitValue) - 1.0f);
204  }
205 
206  static float SinusoidalCenter(float unitValue)
207  {
208  if (unitValue < 0.5f)
209  {
210  return (0.5f * sin(PI * unitValue));
211  }
212  else
213  {
214  return (-0.5f * (cos(PI * (unitValue-0.5f)) + 1.0f));
215  }
216 
217  }
218 
219  static float ExponentialIn(float unitValue)
220  {
221  return (pow(2, 10.0f * (unitValue - 1.0f)));
222  }
223 
224  static float ExponentialOut(float unitValue)
225  {
226  return (-pow(2, -10.0f * unitValue) + 1.0f);
227  }
228 
229  static float ExponentialInOut(float unitValue)
230  {
231  unitValue *= 2.0f;
232  if (unitValue < 1.0f)
233  {
234  return (0.5f * pow(2, 10.0f * (unitValue - 1.0f)));
235  }
236  else
237  {
238  unitValue -= 1.0f;
239  return (0.5f * (-pow(2, -10.0f * unitValue) + 2.0f));
240  }
241  }
242 
243  static float ExponentialCenter(float unitValue)
244  {
245  unitValue *= 2.0f;
246  if (unitValue < 1.0f)
247  {
248  return (0.5f * (-pow(2, -10.0f * unitValue) + 1.0f));
249  }
250  else
251  {
252  unitValue -= 2.0f;
253  return (0.5f * (pow(2, 10.0f * unitValue) + 1.0f));
254  }
255  }
256 
257  static float CircularIn(float unitValue)
258  {
259  if (unitValue == 1.0f)
260  {
261  return 1.0f;
262  }
263  else
264  {
265  return (-(sqrt(1.0f - unitValue * unitValue) - 1.0f));
266  }
267  }
268 
269  static float CircularOut(float unitValue)
270  {
271  unitValue -= 1.0f;
272  return (sqrt(1.0f - unitValue * unitValue));
273  }
274 
275  static float CircularInOut(float unitValue)
276  {
277  unitValue *= 2.0f;
278  if (unitValue < 1.0f)
279  {
280  return (-0.5f * (sqrt(1.0f - unitValue * unitValue) - 1.0f));
281  }
282  else
283  {
284  unitValue -= 2.0f;
285  return (0.5f * (sqrt(1.0f - unitValue * unitValue) + 1.0f));
286  }
287  }
288 
289  static float CircularCenter(float unitValue)
290  {
291  unitValue *= 2.0f;
292  unitValue -= 1.0f;
293 
294  if (unitValue < 0.0f)
295  {
296  return (0.5f * sqrt(1.0f - unitValue * unitValue));
297  }
298  else if (unitValue > 0.0f)
299  {
300  unitValue -= 2.0f;
301  return (-0.5f * (sqrt(1.0f - unitValue * unitValue) - 1.0f ) + 0.5f);
302  }
303  else
304  {
305  return 1.0f;
306  }
307  }
308 
309  static float Gamma(float unitValue)
310  {
311  return pow(unitValue, 1.0f / 0.45f);
312  }
313 
314  static float GammaCieLab(float unitValue)
315  {
316  if (unitValue <= 0.08f)
317  {
318  return unitValue / 9.033f;
319  }
320  else
321  {
322  return pow((unitValue + 0.16f) / 1.16f, 3.0f);
323  }
324  }
325 };
std::function< float(float unitValue)> AnimEaseFunction
Definition: NeoEase.h:38
Definition: NeoEase.h:43
static float CubicOut(float unitValue)
Definition: NeoEase.h:93
static float QuarticCenter(float unitValue)
Definition: NeoEase.h:145
static float QuinticOut(float unitValue)
Definition: NeoEase.h:164
static float QuinticIn(float unitValue)
Definition: NeoEase.h:159
static float CircularInOut(float unitValue)
Definition: NeoEase.h:275
static float QuinticCenter(float unitValue)
Definition: NeoEase.h:184
static float CircularOut(float unitValue)
Definition: NeoEase.h:269
static float CircularCenter(float unitValue)
Definition: NeoEase.h:289
static float CircularIn(float unitValue)
Definition: NeoEase.h:257
static float ExponentialIn(float unitValue)
Definition: NeoEase.h:219
static float CubicInOut(float unitValue)
Definition: NeoEase.h:99
static float Gamma(float unitValue)
Definition: NeoEase.h:309
static float ExponentialInOut(float unitValue)
Definition: NeoEase.h:229
static float Linear(float unitValue)
Definition: NeoEase.h:45
static float QuadraticIn(float unitValue)
Definition: NeoEase.h:50
static float SinusoidalOut(float unitValue)
Definition: NeoEase.h:196
static float QuarticIn(float unitValue)
Definition: NeoEase.h:120
static float CubicIn(float unitValue)
Definition: NeoEase.h:88
static float ExponentialCenter(float unitValue)
Definition: NeoEase.h:243
static float QuinticInOut(float unitValue)
Definition: NeoEase.h:170
static float QuadraticOut(float unitValue)
Definition: NeoEase.h:55
static float SinusoidalIn(float unitValue)
Definition: NeoEase.h:191
static float QuadraticInOut(float unitValue)
Definition: NeoEase.h:60
static float SinusoidalCenter(float unitValue)
Definition: NeoEase.h:206
static float QuarticInOut(float unitValue)
Definition: NeoEase.h:131
static float QuarticOut(float unitValue)
Definition: NeoEase.h:125
static float QuadraticCenter(float unitValue)
Definition: NeoEase.h:74
static float CubicCenter(float unitValue)
Definition: NeoEase.h:113
static float ExponentialOut(float unitValue)
Definition: NeoEase.h:224
static float GammaCieLab(float unitValue)
Definition: NeoEase.h:314
static float SinusoidalInOut(float unitValue)
Definition: NeoEase.h:201