Created
October 31, 2013 08:58
-
-
Save carambula/7246404 to your computer and use it in GitHub Desktop.
Convert a number within a range to a different range. For instance, 3 on a 1-10 scale to a 1-100 scale. Handy for pegging something like alpha (0-1 range) to an x coordinate (0-width of space)
This file contains hidden or 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
| function convertRange(OldMin, OldMax, OldValue, NewMin, NewMax){ | |
| var OldRange = OldMax - OldMin; | |
| var NewRange = NewMax - NewMin; | |
| return (((OldValue - OldMin) * NewRange) / OldRange) + NewMin; | |
| } | |
| newOpacity = convertRange(0, 10, 3, 0, 100) | |
| console.log (newOpacity) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment