运动公式类

  1. package{
  2.     
  3.     public class Tweens{
  4.         
  5.         public function Tweens(){}
  6.         /*
  7.         time:运动初始时间,一般为零
  8.         begin:运动对象的初始属性 
  9.         change:运动对象属性的改变量 
  10.         duration:运动持续时间
  11.         */
  12.         //直线运动
  13.         function lineMove(time:Number,begin:Number,change:Number,duration:Number):Number 
  14.                  { return change * time / duration + begin;}
  15.         
  16.         //二次缓入 
  17.         function easeInQuad(time:Number,begin:Number,change:Number,duration:Number):Number 
  18.                  { return change * (time /=duration)*time + begin; } 
  19.         
  20.         //二次缓出 
  21.         function easeOutQuad(time:Number,begin:Number,change:Number,duration:Number):Number
  22.                  { return -change * (time /=duration)*(time-2) + begin; }
  23.         
  24.         //二次缓入-缓出 
  25.          function easeOutQuad(time:Number,begin:Number,change:Number,duration:Number):Number
  26.                  { if((time/=duration/2)<1)return change/2*time*time+begin 
  27.                    return -change/2 *((--time)*(time-2)-1)+begin }
  28.         
  29.         //正弦缓动
  30.          function easeInSine(time:Number,begin:Number,change:Number,duration:Number):Number
  31.                  { return change*(1-Math.cos(time/duration*(Math.PI/2)))+begin} 
  32.          function easeOutSine(time:Number,begin:Number,change:Number,duration:Number):Number
  33.                  { return change*(1-Math.sin(time/duration*(Math.PI/2)))+begin}
  34.         function easeInOutSine(time:Number,begin:Number,change:Number,duration:Number):Number
  35.                  { return change/2*(1-Math.cos(Math.PI*time/duration))+begin} 
  36.         
  37.         //圆形缓动
  38.         function easeInCirc(time:Number,begin:Number,change:Number,duration:Number):Number
  39.                   { return change*(1-Math.sqrt(1-(time/=duration)*time))+begin} 
  40.         function easeOutCirc(time:Number,begin:Number,change:Number,duration:Number):Number
  41.                  { return change*Math.sqrt(1-(time=time/duration-1)*time)+begin} 
  42.         function easeInOutCirc(time:Number,begin:Number,change:Number,duration:Number):Number
  43.                  { if((time/=duration/2)<1){return change/2*(1-Math.sqrt(1-time*time))+begin}
  44.                     return change/2*(Math.sqrt(1-(time-=2)*time)+1)+begin} 
  45.         //指数缓动
  46.         function easeInExpo(time:Number,begin:Number,change:Number,duration:Number):Number
  47.                  { return change*Math.pow(2,10*(time/duration-1))+begin}
  48.         function easeOutCirc(time:Number,begin:Number,change:Number,duration:Number):Number
  49.                  { return change*(Math.pow(2,-10*time/duration)+1)+begin} 
  50.         function easeInOutCirc(time:Number,begin:Number,change:Number,duration:Number):Number
  51.                  { if((time/=duration/2)<1){return Math.pow(2,10*(time-1))+begin}
  52.                     return change/2*(-Math.pow(2,-10*--time)+2)+begin} 
  53.         /*
  54.         
  55.         obj:运动对象
  56.         pertype:运动对象属性
  57.         begin:运动对象属性初始状态
  58.         center:运动中心
  59.         factot:运动摩擦系数
  60.         
  61.         */
  62.                     
  63.                     
  64.         //简谐运动 
  65.         function harmonic(obj:*,pertype:String,begin:Number,center:Number,factor:Number):Number{
  66.             obj.speed = 0;
  67.             obj.pertype=pertype
  68.             obj.begin=begin
  69.             obj.center=center
  70.             obj.factor=factor
  71.             obj.onEnterFrame = function() {
  72.                  this.speed += (this.center-this.begin)*this.factor 
  73.                  this[this.pertype] += this.speed;
  74.                  }; 
  75.             }
  76.         //摩差运动的缓冲 
  77.         function buffer(obj:*,pertype:String,begin:Number,center:Number,factor:Number):Number{
  78.             obj.pertype=pertype
  79.             obj.begin=begin
  80.             obj.center=center
  81.             obj.factor=factor
  82.             obj.onEnterFrame = function() {
  83.                  this[this.pertype] += (this.center-this.begin)*this.factor 
  84.                  }; 
  85.             }
  86.         //阻尼运动 
  87.         /*
  88.         
  89.         obj:运动对象
  90.         pertype:运动对象属性
  91.         r:阻尼运动半径
  92.         ang: 阻尼运动角度
  93.         factot:阻尼运动系数
  94.         
  95.         */
  96.                     
  97.         function damping(obj:*,pertype:String,r:Number,ang:Number,factor:Number):Number{
  98.             obj.pertype=pertype
  99.             obj.r=r
  100.             obj.ang=ang
  101.             obj.factor=factor
  102.             obj.onEnterFrame = function() {
  103.                  this[this.pertype] += Math.sin(this.ang)*this.r*this.factor
  104.                  this.ang+=1
  105.                  }; 
  106.             }
  107.         }
  108.     
  109.     }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值