16constexpr float kPi = 3.14159265358979323846f;
17constexpr float kPi2 = kPi / 2.f;
44 return -(p * (p - 2.f));
51 return p < 0.5f ? 2.f * p * p : (-2.f * p * p) + (4.f * p) - 1.f;
61 const float f = (p - 1.f);
62 return f * f * f + 1.f;
70 return 4.f * p * p * p;
72 const float f = ((2.f * p) - 2.f);
73 return 0.5f * f * f * f + 1.f;
83 const float f = (p - 1.f);
84 return f * f * f * (1.f - p) + 1.f;
92 return 8.f * p * p * p * p;
94 const float f = (p - 1.f);
95 return -8.f * f * f * f * f + 1.f;
100 return p * p * p * p * p;
105 const float f = (p - 1.f);
106 return f * f * f * f * f + 1.f;
114 return 16.f * p * p * p * p * p;
116 const float f = ((2.f * p) - 2.f);
117 return 0.5f * f * f * f * f * f + 1.f;
122 return std::sin((p - 1.f) * kPi2) + 1.f;
127 return std::sin(p * kPi2);
132 return 0.5f * (1.f - std::cos(p * kPi));
137 return 1.f - std::sqrt(1.f - (p * p));
142 return std::sqrt((2.f - p) * p);
150 return 0.5f * (1.f - std::sqrt(1.f - 4.f * (p * p)));
152 return 0.5f * (std::sqrt(-((2.f * p) - 3.f) * ((2.f * p) - 1.f)) + 1.f);
157 return (p == 0.f) ? p : std::pow(2.f, 10.f * (p - 1.f));
162 return (p == 1.f) ? p : 1.f - std::pow(2.f, -10.f * p);
169 if (p == 0.f || p == 1.f) {
174 return 0.5f * std::pow(2.f, (20.f * p) - 10.f);
176 return -0.5f * std::pow(2.f, (-20.f * p) + 10.f) + 1.f;
182 return std::sin(13.f * kPi2 * p) * std::pow(2.f, 10.f * (p - 1.f));
189 return std::sin(-13.f * kPi2 * (p + 1.f)) * std::pow(2.f, -10.f * p) + 1.f;
197 return 0.5f * std::sin(13.f * kPi2 * (2.f * p)) *
198 std::pow(2.f, 10.f * ((2.f * p) - 1.f));
200 return 0.5f * (std::sin(-13.f * kPi2 * ((2.f * p - 1.f) + 1.f)) *
201 std::pow(2.f, -10.f * (2.f * p - 1.f)) +
207 return p * p * p - p * std::sin(p * kPi);
212 const float f = (1.f - p);
213 return 1.f - (f * f * f - f * std::sin(f * kPi));
221 const float f = 2.f * p;
222 return 0.5f * (f * f * f - f * std::sin(f * kPi));
224 const float f = (1.f - (2.f * p - 1.f));
225 return 0.5f * (1.f - (f * f * f - f * std::sin(f * kPi))) + 0.5f;
233 if (p < 4.f / 11.f) {
234 return (121.f * p * p) / 16.f;
237 if (p < 8.f / 11.f) {
238 return (363.f / 40.f * p * p) - (99.f / 10.f * p) + 17.f / 5.f;
241 if (p < 9.f / 10.f) {
242 return (4356.f / 361.f * p * p) - (35442.f / 1805.f * p) + 16061.f / 1805.f;
245 return (54.f / 5.f * p * p) - (513 / 25.f * p) + 268 / 25.f;
252 return 0.5f *
BounceOut(p * 2.f - 1.f) + 0.5f;
257Animator::Animator(
float* from,
266 easing_function_(std::move(easing_function)),
271void Animator::OnAnimation(Params& params) {
272 current_ += params.duration();
274 if (current_ >= duration_) {
282 *
value_ = from_ + (to_ - from_) * easing_function_(current_ / duration_);
285 RequestAnimationFrame();
The FTXUI ftxui::animation::easing:: namespace.
float CircularInOut(float p)
float BounceInOut(float p)
float CubicInOut(float p)
float Linear(float p)
Modeled after the line y = x.
float CircularOut(float p)
float ExponentialInOut(float p)
float ElasticInOut(float p)
float QuarticInOut(float p)
float QuadraticInOut(float p)
float QuarticOut(float p)
float CircularIn(float p)
float ExponentialOut(float p)
float QuadraticOut(float p)
float QuinticOut(float p)
float QuadraticIn(float p)
Modeled after the parabola y = x^2.
float ExponentialIn(float p)
float ElasticOut(float p)
std::function< float(float)> Function
float QuinticInOut(float p)
std::chrono::duration< float > Duration
void RequestAnimationFrame()