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 rescalein0the start of the input rangein1the end of the input rangeout0the start of the output rangeout1the end of the output rangeExample
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
}
}