Skip to content

Instantly share code, notes, and snippets.

View mattlundstrom's full-sized avatar

Matt Lundstrom mattlundstrom

View GitHub Profile
@mattlundstrom
mattlundstrom / Bilnear Interpolation
Last active December 22, 2015 22:59
Bilnear Interpolation
bilerp(s,t) = t*(s*p3+(1-s)*p2) + (1-t)*(s*p1+(1-s)*p0)
@mattlundstrom
mattlundstrom / Request Animation Frame
Last active December 22, 2015 00:59 — forked from paulirish/rAF.js
Request Animation Frame
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
var mouse = {
down: false,
x: 0,
y: 0
};
canvas.onmousedown = function(e) {
mouse.down = true;
return false;
};
// Created by STRd6
// MIT License
// jquery.paste_image_reader.js
(function($) {
var defaults;
$.event.fix = (function(originalFix) {
return function(event) {
event = originalFix.apply(this, arguments);
if (event.type.indexOf('copy') === 0 || event.type.indexOf('paste') === 0) {
event.clipboardData = event.originalEvent.clipboardData;
@mattlundstrom
mattlundstrom / Get Javascript Object Type
Last active December 21, 2015 20:39
Get Javascript Object Type
function type(obj){
return Object.prototype.toString.call(obj).slice(8, -1);
}
@mattlundstrom
mattlundstrom / Execute Function By Name
Last active December 21, 2015 20:39
Execute Function By Name
function executeFunctionByName(functionName, context /*, args */) {
var args = Array.prototype.slice.call(arguments).splice(2);
var namespaces = functionName.split(".");
var func = namespaces.pop();
for(var i = 0; i < namespaces.length; i++) {
context = context[namespaces[i]];
}
return context[func].apply(this, args);
}
var Easing = {
easeInQuad: function (t, b, c, d) {
return c*(t/=d)*t + b;
},
easeOutQuad: function (t, b, c, d) {
return -c *(t/=d)*(t-2) + b;
},
easeInOutQuad: function (t, b, c, d) {
if ((t/=d/2) < 1) return c/2*t*t + b;
random: function( min, max ) {
if ( isArray( min ) )
return min[ ~~( M.random() * min.length ) ];
if ( !isNumber( max ) )
max = min || 1, min = 0;
@mattlundstrom
mattlundstrom / gist:6345921
Created August 26, 2013 19:57
Map a value from one range to another
function map(_val, _min1, _max1, _min2, _max2)
{
return ((_val - _min1)/(_max1 - _min1)) * (_max2 - _min2) + _min2;
}
var Color = function() {
this.r = this.g = this.b = 0;
this.h = this.s = this.l = 0;
this.a = 1;
};
/** RGB */
Color.prototype.cssRGB = function() {
return "rgb("+Math.round(255*this.r)+","+Math.round(255*this.g)+","+Math.round(255*this.b)+")";
};
Color.prototype.cssRGBA = function() {