Maps a number from one range to another range.

Returns n mapped between outMinoutMax from inMininMax.

代码实现

num mapNumRange(num n, num inMin, num inMax, num outMin, num outMax) {
  return ((n - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;
}

使用样例

mapNumRange(5, 0, 10, 0, 100); // 50