forked from Abacus/Abacus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2. Simple tests for tweening 3. build.json changes for tween lib 4. Abacus core file
- Loading branch information
1 parent
811872d
commit 8eef005
Showing
6 changed files
with
106 additions
and
8 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
(function( window ) { | ||
|
||
var Abacus = window.Abacus || {}; | ||
|
||
Abacus.guid = function() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | ||
return v.toString(16); | ||
}).toUpperCase(); | ||
}; | ||
|
||
// Re-expose Abacus object | ||
window.Abacus = Abacus; | ||
|
||
})( this ); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(function( window ) { | ||
|
||
var types = { | ||
"linear": function( start, stop, index ) { | ||
return ( stop - start ) * index + start; | ||
} | ||
}; | ||
|
||
function Tween( options ) { | ||
|
||
options = options || {}; | ||
|
||
var tweenFunction; | ||
|
||
this.index = options.index || 0; | ||
this.start = options.start || 0; | ||
this.stop = options.stop || 0; | ||
|
||
function chooseTweenFunction( tween ) { | ||
if ( tween ) { | ||
var tweenParamType = typeof( tween ); | ||
if ( tweenParamType === "string" ) { | ||
tweenFunction = types[ tween ] || function() {}; | ||
} | ||
else if ( tweenParamType === "function" ) { | ||
tweenFunction = tween; | ||
} | ||
else { | ||
tweenFunction = function(){}; | ||
} | ||
} | ||
else { | ||
tweenFunction = function(){}; | ||
} | ||
} //chooseTweenFunction | ||
|
||
this.get = function( preferredIndex ) { | ||
this.index = preferredIndex || this.index; | ||
return tweenFunction( this.start, this.stop, this.index ); | ||
}; //step | ||
|
||
Object.defineProperty( this, "type", { | ||
get: function() { | ||
return tweenFunction; | ||
}, | ||
set: function( val ) { | ||
chooseTweenFunction( val ); | ||
} | ||
}); | ||
|
||
chooseTweenFunction( options.type ); | ||
|
||
} //Tween | ||
|
||
window.Abacus.tween = function( options ) { | ||
return new Tween( options ); | ||
}; | ||
|
||
})( this ); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module('Tween Module'); | ||
test('Test that the Abacus.tween exists', 1, function() { | ||
ok( Abacus.tween, 'Abacus.tween exists' ); | ||
}); | ||
|
||
test('Tween instances have step method', 1, function() { | ||
var tween = Abacus.tween(); | ||
equal( typeof tween.get, 'function', 'the tween instance has a get method' ); | ||
}); | ||
|
||
test('Linear Tween is correct', 3, function() { | ||
var tween = Abacus.tween({ | ||
type: "linear", | ||
start: 6, | ||
stop: 8 | ||
}); | ||
|
||
equal( tween.get( 0 ), 6, 'get(0) is correct' ); | ||
equal( tween.get( 1 ), 8, 'get(1) is correct' ); | ||
equal( tween.get( .5 ), 7, 'get(.5) is correct' ); | ||
}); | ||
|
||
|