Created
September 26, 2022 20:37
-
-
Save diegovgsilva95/ec78bcb87b6763b4c71c5a87a66d857a to your computer and use it in GitHub Desktop.
Map number
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
| export function mapNumber(v, fn, fx, tn, tx, constrain = true){ | |
| if(fx == fn) | |
| return v < fn ? tn : tx; | |
| v = (v - fn) / (fx - fn); | |
| if(constrain) | |
| v = Math.min(1, Math.max(0, v)); | |
| return ((v * (tx - tn)) + tn); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment