1use ::std::f32::consts::PI;
2
3const C4: f32 = (2.0 * PI) / 3.0;
4const C5: f32 = (2.0 * PI) / 4.5;
5
6pub fn elastic_in(t: f32) -> f32 {
8 if t <= 0.0 {
9 0.0
10 } else if 1.0 <= t {
11 1.0
12 } else {
13 -2f32.powf(10.0 * t - 10.0) * ((t * 10.0 - 10.75) * C4).sin()
14 }
15}
16
17pub fn elastic_out(t: f32) -> f32 {
19 if t <= 0.0 {
20 0.0
21 } else if 1.0 <= t {
22 1.0
23 } else {
24 2f32.powf(-10.0 * t) * ((t * 10.0 - 0.75) * C4).sin() + 1.0
25 }
26}
27
28pub fn elastic_in_out(t: f32) -> f32 {
30 if t <= 0.0 {
31 0.0
32 } else if 1.0 <= t {
33 1.0
34 } else if t < 0.5 {
35 -(2f32.powf(20.0 * t - 10.0) * ((20.0 * t - 11.125) * C5).sin()) / 2.0
36 } else {
37 (2f32.powf(-20.0 * t + 10.0) * ((20.0 * t - 11.125) * C5).sin()) / 2.0 + 1.0
38 }
39}