API Reference › Math › Math.remap
method

Math.remap

Math.remap(v, in0, in1, out0, out1) -> fixed

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

vthe value to rescale
in0the start of the input range
in1the end of the input range
out0the start of the output range
out1the end of the output range

Example

program HealthBar {
  const MAX_HP: fixed = 200.0
  const BAR_WIDTH: fixed = 64.0

  var hp: fixed = 150.0

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