Last active
November 12, 2015 02:25
-
-
Save Meandmybadself/097ed63035d7d8d7e6a8 to your computer and use it in GitHub Desktop.
JavaScript utility belt
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
//A continual schmorgasboard of code that probably exists in a better documented & executed function elsewhere. | |
//Produces a # between min and max. | |
function between(min,max) { | |
var d = Math.abs(min - max); | |
return min + Math.random() * d; | |
} | |
//Integer between min & max. | |
function intBetween(min,max) { | |
return Math.floor(between(min,max)) | |
} | |
function mapValue(per, min, max) { | |
var diff = max - min; | |
return min + (diff * per * 2); | |
} | |
//Produces a number from 0 - max | |
function ranRange(max) { | |
return -max + (Math.random() * (max * 2)); | |
} | |
//Degrees to radians. | |
function deg2rad(d) { | |
return d * (Math.PI / 180); | |
} | |
//The other way around. | |
function rad2deg(r) { | |
return r * (180 / Math.PI); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment