mapbox-gl
Version:
A WebGL interactive maps library
40 lines (33 loc) • 870 B
JavaScript
;
module.exports = interpolate;
function interpolate(a, b, t) {
return (a * (1 - t)) + (b * t);
}
interpolate.number = interpolate;
interpolate.vec2 = function(from, to, t) {
return [
interpolate(from[0], to[0], t),
interpolate(from[1], to[1], t)
];
};
/*
* Interpolate between two colors given as 4-element arrays.
*
* @param {Color} from
* @param {Color} to
* @param {number} t interpolation factor between 0 and 1
* @returns {Color} interpolated color
*/
interpolate.color = function(from, to, t) {
return [
interpolate(from[0], to[0], t),
interpolate(from[1], to[1], t),
interpolate(from[2], to[2], t),
interpolate(from[3], to[3], t)
];
};
interpolate.array = function(from, to, t) {
return from.map(function(d, i) {
return interpolate(d, to[i], t);
});
};