src/mousetracker.js
function () {
            var i,
                len = trackerPoints.length,
                trackPoint,
                gPoint,
                now = $.now(),
                elapsedTime,
                distance,
                speed;

            elapsedTime = now - lastTime;
            lastTime = now;

            for ( i = 0; i < len; i++ ) {
                trackPoint = trackerPoints[ i ];
                gPoint = trackPoint.gPoint;
                // Math.atan2 gives us just what we need for a velocity vector, as we can simply
                //   use cos()/sin() to extract the x/y velocity components.
                gPoint.direction = Math.atan2( gPoint.currentPos.y - trackPoint.lastPos.y, gPoint.currentPos.x - trackPoint.lastPos.x );
                // speed = distance / elapsed time
                distance = trackPoint.lastPos.distanceTo( gPoint.currentPos );
                trackPoint.lastPos = gPoint.currentPos;
                speed = 1000 * distance / ( elapsedTime + 1 );
                // Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.
                gPoint.speed = 0.75 * speed + 0.25 * gPoint.speed;
            }
        }
function () {
            var i,
                len = trackerPoints.length,
                trackPoint,
                gPoint,
                now = $.now(),
                elapsedTime,
                distance,
                speed;

            elapsedTime = now - lastTime;
            lastTime = now;

            for ( i = 0; i < len; i++ ) {
                trackPoint = trackerPoints[ i ];
                gPoint = trackPoint.gPoint;
                // Math.atan2 gives us just what we need for a velocity vector, as we can simply
                //   use cos()/sin() to extract the x/y velocity components.
                gPoint.direction = Math.atan2( gPoint.currentPos.y - trackPoint.lastPos.y, gPoint.currentPos.x - trackPoint.lastPos.x );
                // speed = distance / elapsed time
                distance = trackPoint.lastPos.distanceTo( gPoint.currentPos );
                trackPoint.lastPos = gPoint.currentPos;
                speed = 1000 * distance / ( elapsedTime + 1 );
                // Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit.
                gPoint.speed = 0.75 * speed + 0.25 * gPoint.speed;
            }
        }
function ( ) { var i , len = trackerPoints . length , trackPoint , gPoint , now = $ . now ( ) , elapsedTime , distance , speed ; elapsedTime = now - lastTime ; lastTime = now ; for ( i = 0 ; i < len ; i ++ ) { trackPoint = trackerPoints [ i ] ; gPoint = trackPoint . gPoint ; // Math.atan2 gives us just what we need for a velocity vector, as we can simply //   use cos()/sin() to extract the x/y velocity components. gPoint . direction = Math . atan2 ( gPoint . currentPos . y - trackPoint . lastPos . y , gPoint . currentPos . x - trackPoint . lastPos . x ) ; // speed = distance / elapsed time distance = trackPoint . lastPos . distanceTo ( gPoint . currentPos ) ; trackPoint . lastPos = gPoint . currentPos ; speed = 1000 * distance / ( elapsedTime + 1 ) ; // Simple biased average, favors the most recent speed computation. Smooths out erratic gestures a bit. gPoint . speed = 0.75 * speed + 0.25 * gPoint . speed ; } }
Interval timer callback. Computes velocity for all tracked gesture points.
Interval timer callback . Computes velocity for all tracked gesture points .