// Please consider to go to the stackoverflow link and give the guy that answered an upvote function map_range(value, low1, high1, low2, high2) { return low2 + (high2 - low2) * (value - low1) / (high1 - low1); }