philomena/assets/js/utils/lerp.ts

13 lines
468 B
TypeScript
Raw Normal View History

2024-06-03 23:43:51 +02:00
// Simple linear interpolation.
// Returns a value between min and max based on a delta.
// The delta is a number between 0 and 1.
// If the delta is not within the 0-1 range, this function will
// clamp the value between min and max, depending on whether
// the delta >= 1 or <= 0.
export function lerp(delta: number, from: number, to: number): number {
if (delta >= 1) { return to; }
else if (delta <= 0) { return from; }
return from + (to - from) * delta;
}