Lerp

Put the marker a quarter of the way across the bar. Find the matching point between the two rings.
Interactive demo#MotionAndFeel
Finding the value part-way between two others.
Lerp takes a start, an end and a fraction t. At t = 0 you get the start, at 1 the end, at 0.5 the midpoint. It works on anything made of numbers: positions, colours, volume, zoom.
Code
namespace lerp_lesson;
import stage;
import std;
import math;
export "lerp" fn draw(time: f64, dt: f64, px: f64, py: f64, hover: bool) {
artwork("draft");
let amount = if hover { clamp((px - 24) / 112.0, 0.0, 1.0) } else { ease_in_out(pingpong(time * 0.45)) };
line(24, 62, 136, 30, LINE, 3, 3);
ring(24, 62, 5, SKY);
ring(136, 30, 5, SKY);
let x = 24 + (136 - 24) * amount;
let y = 62 + (30 - 62) * amount;
image(0, x - 12, y - 12, 2, "base", "runner");
rect(24, 87, 112, 2, LINE);
rect(24, 87, 112 * amount, 2, MAG);
rect(22 + 112 * amount, 83, 4, 10, MAG);
}

Comments
No comments yet.