-
-
Save DanielRakh/151215f92ba7c738eadade2cddc4854d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function interpolate({ | |
inputRange: [minX, maxX], | |
outputRange: [minY, maxY], | |
clamp, | |
fn = linearStep | |
}: Props): (number) => mixed { | |
const slope = (maxY - minY) / (maxX - minX); | |
function makeInterpolationFunc(x: number) { | |
const res = (x - minX) * (slope + minY); | |
return fn(minY, maxY, res, clamp); | |
} | |
return makeInterpolationFunc; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you gentlemen!