]> git.proxmox.com Git - sencha-touch.git/blob - src/src/fx/easing/Momentum.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / fx / easing / Momentum.js
1 /**
2 * @private
3 */
4 Ext.define('Ext.fx.easing.Momentum', {
5
6 extend: 'Ext.fx.easing.Abstract',
7
8 config: {
9 acceleration: 30,
10 friction: 0,
11 startVelocity: 0
12 },
13
14 alpha: 0,
15
16 updateFriction: function(friction) {
17 var theta = Math.log(1 - (friction / 10));
18
19 this.theta = theta;
20
21 this.alpha = theta / this.getAcceleration();
22 },
23
24 updateStartVelocity: function(velocity) {
25 this.velocity = velocity * this.getAcceleration();
26 },
27
28 updateAcceleration: function(acceleration) {
29 this.velocity = this.getStartVelocity() * acceleration;
30
31 this.alpha = this.theta / acceleration;
32 },
33
34 getValue: function() {
35 return this.getStartValue() - this.velocity * (1 - this.getFrictionFactor()) / this.theta;
36 },
37
38 getFrictionFactor: function() {
39 var deltaTime = Ext.Date.now() - this.getStartTime();
40
41 return Math.exp(deltaTime * this.alpha);
42 },
43
44 getVelocity: function() {
45 return this.getFrictionFactor() * this.velocity;
46 }
47 });