ludic/docs/language/math/math-lerp.md

1.2 KiB

id name category kind tokens sig tip order ns member
math-lerp Math.lerp math namespace-method Math.lerp Math.lerp(a, b, t) -> fixed Blend between two values by a 0..1 amount. 8 Math lerp

Linear interpolation: returns a when t is 0.0, b when t is 1.0, and a proportional blend in between — the exact value a + (b - a) * t. All three arguments are fixed and the result is fixed. It is the workhorse behind smooth motion: ease a camera toward a target, fade a value over time, or sample a gradient. Values of t outside 0..1 extrapolate past the endpoints.

Parameters:

  • a — the value returned at t = 0.0
  • b — the value returned at t = 1.0
  • t — the blend amount, normally 0.0..1.0
program EaseCamera {
  state EaseCameraState {
    camera_x: fixed = 0.0
  }
  let target_x: fixed = 100.0

  handler Follow(ease_camera_st: mut EaseCameraState) phase Update {
    ease_camera_st.camera_x = Math.lerp(ease_camera_st.camera_x, target_x, 0.1)   # glides a tenth of the way each frame
  }
}