Skip to content

Instantly share code, notes, and snippets.

@5andr0
Created August 7, 2018 13:10
Show Gist options
  • Save 5andr0/7c722bd215a0f431f494c91fd7db923c to your computer and use it in GitHub Desktop.
Save 5andr0/7c722bd215a0f431f494c91fd7db923c to your computer and use it in GitHub Desktop.
Javascript Snippets
/* rgbArrayToHex */
function rgbToHex(rgb) {
return "#" + (1 << 24 | rgb[0] << 16 | rgb[1] << 8 | rgb[2]).toString(16).slice(1);
}
/* request variables to object
https://stackoverflow.com/a/21152762/86145
*/
var qd = {};
if (location.search) location.search.substr(1).split("&").forEach(function(item) {var s = item.split("="), k = s[0], v = s[1] && decodeURIComponent(s[1]); (qd[k] = qd[k] || []).push(v)})
/* rng https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random */
/* The returned value is no lower than (and may possibly equal) min, and is less than (and not equal) max */
function getRandomArbitrary(min, max, rand) {
return ((rand === undefined) ? Math.random() : rand) * (max - min) + min;
}
/* random number between min and max (both included) */
function getRandomInt(min, max, rand) {
return Math.floor(getRandomArbitrary(min, max+1, rand));
}
/* Exponential ease between 0 and 1*/
var off = 5; // between 1 and 10 recommended
var factor = 1-(Math.exp(-off*(index/length)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment