Skip to content

Instantly share code, notes, and snippets.

@Meandmybadself
Last active November 12, 2015 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Meandmybadself/097ed63035d7d8d7e6a8 to your computer and use it in GitHub Desktop.
Save Meandmybadself/097ed63035d7d8d7e6a8 to your computer and use it in GitHub Desktop.
JavaScript utility belt
//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