Squash and stretch

Pause at the landing. Toggle the effect and compare the width of the two poses.
Interactive demo#MotionAndFeel
Stretching a sprite when it moves fast and squashing it on impact.
An animation principle borrowed from cartoons. The sprite gets taller in the air and flattens when it lands, keeping roughly the same area. Turn it off and the same bounce looks like a rigid cut-out.
Code
namespace squash_and_stretch_lesson;
import stage;
import std;
import math;
export "squash-and-stretch" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("hall", 0, 0, W, 106);
let t = time % 1.0;
let height = 184 * t * (1 - t);
let near = min(t, 1.0 - t) / 0.1;
var stretch = 1.0;
if toggle("on") {
stretch = if near < 1 { mix_value(0.6, 1.22, near) } else { mix_value(1.22, 0.96, 1 - abs(1.0 - 2 * t) / 0.8) };
}
ground(66);
ell(80, 82, 16 * (1 - height / 90), 4 * (1 - height / 90), "rgba(14,15,38,.55)");
sprite(if near < 0.7 { LAND } else { air_pose(184 * (1 - 2 * t)) }, 80, 83 - height, 3 / stretch, 3 * stretch, "base", "runner", 0, 6, 12, false);
}

Comments
No comments yet.