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
/* | |
val = value to snap | |
inc = increment to snap to | |
example: | |
snapToIncrement(10, 3): 9 | |
snapToIncrement(89, 10): 100 | |
snapToIncrement(35.6, .5): 35.5 | |
*/ |
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
var func = function( props ){ | |
props = (typeof props !== "object") ? {} : props; | |
var mx = props.mx || 10; | |
var my = props.my || 10; | |
var mz = props.mz || 10; | |
var time = props.time || 1; | |
var delay = props.delay || 0; | |
var ease = props.ease || Linear.easeNone; |
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
function RectCircleColliding(circle,rect){ | |
var distX = Math.abs(circle.x - rect.x-rect.w/2); | |
var distY = Math.abs(circle.y - rect.y-rect.h/2); | |
if (distX > (rect.w/2 + circle.r)) { return false; } | |
if (distY > (rect.h/2 + circle.r)) { return false; } | |
if (distX <= (rect.w/2)) { return true; } | |
if (distY <= (rect.h/2)) { return true; } |
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
// ONCE | |
function once(fn, context) { | |
var result; | |
return function() { | |
if(fn) { | |
result = fn.apply(context || this, arguments); | |
fn = null; | |
} |
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
// FROM http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame | |
In your main page: | |
var frame = document.getElementById('your-frame-id'); | |
frame.contentWindow.postMessage(/*any variable or object here*/, '*'); | |
In your <iframe> (contained in the main page): | |
window.addEventListener('message', function(event) { |
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
<body onload=setInterval('for(r.width=j=150,i=j*j;--i;)r.getContext(\'2d\').fillRect(i%j,i/j,1,Math.random())',9)><canvas id=r> |
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
Object.getOwnPropertyNames(Math).map(function(p) { | |
window[p] = Math[p]; | |
}); | |
// So instead of Math.random(), just use random(); |
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
function randomRange(min, max) { | |
return min + Math.random() * (max - min); | |
} | |
function randomWeightedRange(min, max, expo) { | |
return toDecimal(((Math.random() * (max - min)) + min), expo); | |
} | |
function randomInt(min, max) { | |
return Math.floor(min + Math.random() * (max - min + 1)); |
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
function clamp( value, min, max ){ | |
return Math.min( Math.max( value, min ), max ); | |
} |
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
function randomInt(min,max) { | |
return Math.floor( min + Math.random() * (max - min + 1) ) | |
} |
NewerOlder