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

1.2 KiB

id name category kind tokens sig tip order ns member
math-remap Math.remap math namespace-method Math.remap Math.remap(v, in0, in1, out0, out1) -> fixed Rescale a value from one range into another. 10 Math remap

Maps v from the input range in0..in1 onto the output range out0..out1, keeping its relative position — equivalent to Math.lerp(out0, out1, Math.inverse_lerp(in0, in1, v)). All arguments are fixed. It is the one call that converts between units: a health value into a bar width, a noise sample in -1..1 into a 0..255 shade, or a mouse position into a world coordinate. Swap the output ends to invert the mapping.

Parameters:

  • v — the value to rescale
  • in0 — the start of the input range
  • in1 — the end of the input range
  • out0 — the start of the output range
  • out1 — the end of the output range
program HealthBar {
  const MAX_HP: fixed = 200.0
  const BAR_WIDTH: fixed = 64.0

  let hp: fixed = 150.0

  handler Draw phase Render {
    let width = Math.remap(hp, 0.0, MAX_HP, 0.0, BAR_WIDTH)   # 48.0
  }
}