range-mapper
v1.0.0
Published
create linear interpolators specifying input and output-ranges.
Downloads
3
Maintainers
Readme
range-mapper
provides simple range-mapping functions for linear-interpolation.
installation
npm install range-mapper
usage
var rangeMapper = require('range-mapper');
var interpolate;
// convert [0..1] to [0..255]
interpolate = rangeMapper(0, 1, 0, 255);
interpolate(0); // > 0
interpolate(1); // > 255
interpolate(0.5); // > 127.5
// no clamping:
interpolate(-1); // > -255
// convert relative coordinates
interpolate = rangeMapper.clamped(0, elementWidth, -1, 1);
// could be used to get relative coordinates for mouse-events
interpolate(ev.pageX - elementLeft);