# 【程序化动画の弹簧】
可以让缓动线性缓动变得Q弹。
以下是曲线参数可视化:
module vp
{
/**
* 弹簧的动画
*/
export class SpringAnimation
{
/** 初始速度 */
private initVelocity:number = 30;
/** 当前速度 */
private velocity: number = 30;
/** 当前位移值 */
private displacement:number = 0;
/** 弹性(值越大幅度越大) */
private spring:number = 900;
/** 阻尼(值越大越快静止) */
private damp:number = 8;
constructor()
{
}
public init(spring:number, damp:number,velocity:number,displacement:number = 0)
{
this.spring = spring;
this.damp = damp;
this.velocity = velocity;
this.initVelocity = this.velocity;
this.displacement = displacement;
}
public replay():void
{
this.velocity = this.initVelocity;
}
/**
* T:每帧经过的时间
*
*/
public update(T:number):number
{
var force = -this.spring * this.displacement - this.damp * this.velocity;
this.velocity += force * T;
this.displacement += this.velocity * T;
return this.displacement;
}
}
}