0:01 / 0:30
Playback speed

Easing

Watch the last stretch of each ball’s journey. Which one crosses its destination and comes back?

#MotionAndFeel

Changing speed along the way, so motion starts and stops naturally.

All three balls leave and arrive at the same moment. The top one moves at constant speed and feels robotic. The middle eases in and out. The bottom overshoots and settles. The small graphs are the curves.

Code

src/demos/easing.goose
namespace easing_lesson;
import stage;
import std;
import math;

fn curve(index: i64, t: f64) -> f64 {
    let back = t - 1;
    match index {
        0 => t,
        1 => ease_in_out(t),
        _ => 1 + 2.7 * back * back * back + 1.7 * back * back,
    }
}

export "easing" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
    artwork("draft");
    let u = clamp((time % 2.6) / 1.9, 0.0, 1.0);
    for i in 3 {
        let y = 20 + i * 30;
        rect(6, y - 10, 26, 20, BG2);
        for k in 25 {
            rect(7 + k, y + 7 - curve(i, k / 24.0) * 13, 1, 1, WHITE);
        }
        rect(7 + u * 24, y - 10, 1, 20, MAG);
        rect(44, y, 106, 1, "#698797");
        ring(142, y, 4, "#77909b", 1, 2);
        draw_prop("marble", 40 + curve(i, u) * 96, y - 6, 12, 12);
    }
}

Stage drawing helpers · All demos on GitHub

Comments

No comments yet.