map.js 302 B

1234567891011
  1. var lerp = require('./lerp');
  2. var norm = require('./norm');
  3. /**
  4. * Maps a number from one scale to another.
  5. * @example map(3, 0, 4, -1, 1) -> 0.5
  6. */
  7. function map(val, min1, max1, min2, max2){
  8. return lerp( norm(val, min1, max1), min2, max2 );
  9. }
  10. module.exports = map;