Skip to content

Instantly share code, notes, and snippets.

View vanrez-nez's full-sized avatar

Ivan Juarez vanrez-nez

View GitHub Profile
@vanrez-nez
vanrez-nez / rgb2Hex.js
Last active August 29, 2015 14:17
Conversion from RGB values to Hex notation
function rgb2Hex(r, g, b) {
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).substr(1);
}
@vanrez-nez
vanrez-nez / clampNumber.js
Last active August 29, 2015 14:15
Clamp number
Number.prototype.clamp = function(min, max) {
return Math.min(Math.max(this, min), max);
};
@vanrez-nez
vanrez-nez / lerp.js
Last active August 29, 2015 14:15
linearly interpolate between two values
//returns the interpolated value from a and b at the given weight (from 0 to 1)
var lerp = function(a, b, w) {
return (1 - w) * a + w * b;
}