1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
/// This module contains the animation related data structures
#[repr(C)]
#[derive(Clone, Copy, Debug)]
pub struct Easing {
pub x1: f32,
pub y1: f32,
pub x2: f32,
pub y2: f32,
}
// default for Easing
impl Default for Easing {
fn default() -> Self {
// Ease out
Easing {
x1: 0.42,
y1: 0.0,
x2: 0.58,
y2: 1.0,
}
}
}
/// Easing functions are used to interpolate between two values
/// over a period of time. The default easing function is ease out.
/// The easing is calculated using a bezier curve with 2 control points.
///
impl Easing {
pub fn ease_out() -> Self {
Easing::default()
}
pub fn ease_in() -> Self {
Easing {
x1: 0.42,
y1: 0.0,
x2: 1.0,
y2: 1.0,
}
}
pub fn ease_in_out() -> Self {
Easing {
x1: 0.42,
y1: 0.0,
x2: 0.58,
y2: 1.0,
}
}
pub fn linear() -> Self {
Easing {
x1: 0.0,
y1: 0.0,
x2: 1.0,
y2: 1.0,
}
}
pub fn ease_out_quad() -> Self {
Easing {
x1: 0.25,
y1: 0.46,
x2: 0.45,
y2: 0.94,
}
}
pub fn ease_in_quad() -> Self {
Easing {
x1: 0.55,
y1: 0.085,
x2: 0.68,
y2: 0.53,
}
}
pub fn ease_in_out_quad() -> Self {
Easing {
x1: 0.455,
y1: 0.03,
x2: 0.515,
y2: 0.955,
}
}
pub fn ease_out_cubic() -> Self {
Easing {
x1: 0.215,
y1: 0.61,
x2: 0.355,
y2: 1.0,
}
}
pub fn ease_in_cubic() -> Self {
Easing {
x1: 0.55,
y1: 0.055,
x2: 0.675,
y2: 0.19,
}
}
pub fn ease_in_out_cubic() -> Self {
Easing {
x1: 0.645,
y1: 0.045,
x2: 0.355,
y2: 1.0,
}
}
pub fn ease_out_quart() -> Self {
Easing {
x1: 0.165,
y1: 0.84,
x2: 0.44,
y2: 1.0,
}
}
pub fn ease_in_quart() -> Self {
Easing {
x1: 0.895,
y1: 0.03,
x2: 0.685,
y2: 0.22,
}
}
pub fn ease_in_out_quart() -> Self {
Easing {
x1: 0.77,
y1: 0.0,
x2: 0.175,
y2: 1.0,
}
}
pub fn ease_out_quint() -> Self {
Easing {
x1: 0.23,
y1: 1.0,
x2: 0.32,
y2: 1.0,
}
}
pub fn ease_in_quint() -> Self {
Easing {
x1: 0.755,
y1: 0.05,
x2: 0.855,
y2: 0.06,
}
}
pub fn ease_in_out_quint() -> Self {
Easing {
x1: 0.86,
y1: 0.0,
x2: 0.07,
y2: 1.0,
}
}
}