Skip to content

Commit b28e894

Browse files
committed
Add some neat new easing functions.
1 parent aa4932e commit b28e894

2 files changed

Lines changed: 46 additions & 7 deletions

File tree

src/dashboard_defs/easing_fns.rs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,27 @@ fn ease_out_bounce(mut x: f64) -> f64 {
2020
}
2121
}
2222

23+
fn snappy(x: f64) -> f64 {
24+
if x < 0.3 {
25+
let p = x / 0.3;
26+
-0.15 * (1.0 - p) * (1.0 - p) // ease back to −0.15
27+
}
28+
else {
29+
let p = (x - 0.3) / 0.7;
30+
// Overshoot curve based on an "outBack" easing with a juicy overshoot
31+
let s = 2.5; // controls overshoot
32+
(p - 1.0) * (p - 1.0) * ((s + 1.0) * (p - 1.0) + s) + 1.0
33+
}
34+
}
35+
36+
fn rubber_band(x: f64) -> f64 {
37+
let freq = 4.0;
38+
let decay = 5.0;
39+
let oscillation = (x * std::f64::consts::PI * freq).sin();
40+
let envelope = (-x * decay).exp();
41+
1.0 - oscillation * envelope
42+
}
43+
2344
//////////
2445

2546
pub mod scroll {
@@ -59,10 +80,10 @@ pub mod scroll {
5980

6081
pub mod transition {
6182
pub mod opacity {
62-
use crate::texture::pool::TextureTransitionOpacityEaser;
83+
use crate::{dashboard_defs::easing_fns::rubber_band, texture::pool::TextureTransitionOpacityEaser};
6384

6485
use super::{
65-
super::ease_out_bounce,
86+
super::{ease_out_bounce, snappy},
6687
aspect_ratio::{STRAIGHT_WAVY as AR_STRAIGHT_WAVY, JITTER_WAVY as AR_JITTER_WAVY}
6788
};
6889

@@ -74,6 +95,12 @@ pub mod transition {
7495
pub const LINEAR_BLENDED_BOUNCE: TextureTransitionOpacityEaser = |percent_done| LINEAR_BLENDED_FADE(ease_out_bounce(percent_done));
7596
pub const BURST_BLENDED_BOUNCE: TextureTransitionOpacityEaser = |percent_done| BURST_BLENDED_FADE(ease_out_bounce(percent_done));
7697

98+
pub const LINEAR_BLENDED_SNAPPY: TextureTransitionOpacityEaser = |percent_done| LINEAR_BLENDED_FADE(snappy(percent_done));
99+
pub const BURST_BLENDED_SNAPPY: TextureTransitionOpacityEaser = |percent_done| BURST_BLENDED_FADE(snappy(percent_done));
100+
101+
pub const LINEAR_BLENDED_RUBBER_BAND: TextureTransitionOpacityEaser = |percent_done| LINEAR_BLENDED_FADE(rubber_band(percent_done));
102+
pub const BURST_BLENDED_RUBBER_BAND: TextureTransitionOpacityEaser = |percent_done| BURST_BLENDED_FADE(rubber_band(percent_done));
103+
77104
pub const STRAIGHT_WAVY: TextureTransitionOpacityEaser = |percent_done| {
78105
let y = AR_STRAIGHT_WAVY(percent_done);
79106
(1.0 - y, y)
@@ -92,11 +119,13 @@ pub mod transition {
92119
}
93120

94121
pub mod aspect_ratio {
95-
use super::super::ease_out_bounce;
96-
use crate::texture::pool::TextureTransitionAspectRatioEaser;
122+
use super::super::{ease_out_bounce, snappy};
123+
use crate::{dashboard_defs::easing_fns::rubber_band, texture::pool::TextureTransitionAspectRatioEaser};
97124

98125
pub const LINEAR: TextureTransitionAspectRatioEaser = |percent_done| percent_done;
99126
pub const BOUNCE: TextureTransitionAspectRatioEaser = ease_out_bounce;
127+
pub const SNAPPY: TextureTransitionAspectRatioEaser = snappy;
128+
pub const RUBBER_BAND: TextureTransitionAspectRatioEaser = rubber_band;
100129

101130
pub const STRAIGHT_WAVY: TextureTransitionAspectRatioEaser = |percent_done| {
102131
const N: u32 = 3;
@@ -197,6 +226,7 @@ macro_rules! generate_proof_group {
197226
generate_proof_group!(
198227
scroll,
199228
crate::dashboard_defs::easing_fns::scroll,
229+
200230
[STAY_PUT, LEFT_LINEAR, OSCILLATE_NO_WRAP, PAUSE_THEN_SCROLL_LEFT]
201231
);
202232

@@ -207,13 +237,16 @@ generate_proof_group!(
207237
[
208238
LINEAR_BLENDED_FADE, BURST_BLENDED_FADE,
209239
LINEAR_BLENDED_BOUNCE, BURST_BLENDED_BOUNCE,
210-
STRAIGHT_WAVY, JITTER_WAVY,
211-
FADE_OUT_THEN_FADE_IN
240+
LINEAR_BLENDED_SNAPPY, BURST_BLENDED_SNAPPY,
241+
LINEAR_BLENDED_RUBBER_BAND, BURST_BLENDED_RUBBER_BAND,
242+
243+
STRAIGHT_WAVY, JITTER_WAVY, FADE_OUT_THEN_FADE_IN
212244
]
213245
);
214246

215247
generate_proof_group!(
216248
aspect_ratio,
217249
crate::dashboard_defs::easing_fns::transition::aspect_ratio,
218-
[LINEAR, BOUNCE, STRAIGHT_WAVY, JITTER_WAVY]
250+
251+
[LINEAR, BOUNCE, SNAPPY, RUBBER_BAND, STRAIGHT_WAVY, JITTER_WAVY]
219252
);

src/dashboard_defs/funky_remake_transitions.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ fn pick_random_easing_pair(rand_generator: &mut rand::rngs::ThreadRng)
4848
(opacity::LINEAR_BLENDED_BOUNCE, aspect_ratio::BOUNCE),
4949
(opacity::BURST_BLENDED_BOUNCE, aspect_ratio::BOUNCE),
5050

51+
(opacity::LINEAR_BLENDED_SNAPPY, aspect_ratio::SNAPPY),
52+
(opacity::BURST_BLENDED_SNAPPY, aspect_ratio::SNAPPY),
53+
54+
(opacity::LINEAR_BLENDED_RUBBER_BAND, aspect_ratio::RUBBER_BAND),
55+
(opacity::BURST_BLENDED_RUBBER_BAND, aspect_ratio::RUBBER_BAND),
56+
5157
(opacity::STRAIGHT_WAVY, aspect_ratio::STRAIGHT_WAVY),
5258
(opacity::JITTER_WAVY, aspect_ratio::JITTER_WAVY)
5359
];

0 commit comments

Comments
 (0)