Skip to content

Instantly share code, notes, and snippets.

View mattlundstrom's full-sized avatar

Matt Lundstrom mattlundstrom

View GitHub Profile
@mattlundstrom
mattlundstrom / rAF.js
Created February 18, 2014 22:49 — forked from paulirish/rAF.js
// 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'];
@mattlundstrom
mattlundstrom / rounding
Last active August 29, 2015 14:01
Rounding
function roundToDecimal( number, decimalPlaces ){
var multiplier = Math.pow( 10, decimalPlaces );
return Math.round( number * multiplier ) / multiplier;
}
function roundNearest( number, nearest ){
return Math.round( number / nearest ) * nearest;
}
drawDottedLine( new Point( 0, 0 ), new Point( 500, 100 ), 0x000000, 1, 3, 0, 1 );
function drawDottedLine( _p1:Point, _p2:Point, _color:uint = 0x000000, _thickness:Number = 1, _gap:Number = 10, _offset:Number = 0, _percent:Number = 1 ):void{
var line:MovieClip = new MovieClip();
addChild( line );
var distance:Number = distance( _p1, _p2 );
@mattlundstrom
mattlundstrom / gist:8c45ac52b71791db5505
Last active August 29, 2015 14:19
Dirty Video Listener 2
// Cuepoints for non flvs
var dirtyVideoListerner:Function = function (_ns:NetStream, _time:Number, _func:Function):void
{
this.addEventListener(Event.ENTER_FRAME, checkTime);
var callingMC:MovieClip = this;
function checkTime():void
{
if (_ns.time > _time)
function randomInt(min,max) {
return Math.floor( min + Math.random() * (max - min + 1) )
}
function clamp( value, min, max ){
return Math.min( Math.max( value, min ), max );
}
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));
@mattlundstrom
mattlundstrom / gist:9047b969679d5ec8e5de
Created September 16, 2015 19:00
Use Math without "Math"
Object.getOwnPropertyNames(Math).map(function(p) {
window[p] = Math[p];
});
// So instead of Math.random(), just use random();
@mattlundstrom
mattlundstrom / gist:2938136
Created June 15, 2012 18:48
Flash Proportional Resize To Fit
function proportionalResizeToFit(resizingMC:Object, referenceMC:Object, useHeight:Boolean){
var origWidth:Number = resizingMC.width;
var origHeight:Number = resizingMC.height;
var ratio:Number = origHeight / origWidth;
if (useHeight){
resizingMC.height = referenceMC.height;
resizingMC.width = resizingMC.height / ratio;
} else {
@mattlundstrom
mattlundstrom / gist:2938102
Created June 15, 2012 18:43
Flash Text Descrambler
var randomChars:String = "A_B_C_D_E_F_G_H_I_J_K_L_M_N_O_P_!_@_#_$_%_^_&_!_ _ _ _ _ _ _"
var charArray:Array = randomChars.split("_");
function descramble(speed:int, txt:TextField):void{
var originalString:String = txt.text;
var newFragment:String;
var newString:String;
var characterNum:int = 0;