[AS3]複数プロパティの対応、終了イベントの発行 < 俺俺TweenエンジンOreOreTweenを作ってみよう3

2010/07/10

こんにちは。きんくまです。
今週はObjective-C頑張ってました。

さて、OreOreTweenです。
今回は複数プロパティの対応と、終了イベントの発行に対応します。

今回作ったものです。
赤い丸はドラッグすることができます。
新たにOPACITY(透明度)のスライダもつけてみました。
ポーズと、レジュームにも対応しました。

 

実は、前回でTweenエンジンは既に完成しているので、残作業をちまちまやっていくだけです。
前回までは、x座標しかTweenすることができなかったので、y座標とか、alphaとかそういうのに対応しましょうという感じです。
そんで、使うときのコードはこんな感じにしました。

			//使い方
			var ore:OreOreTween = new OreOreTween(ball, { 
				x:endPos.x,
				y:endPos.y,
				alpha:opacitySlider.value
				}, duration, easing);
			ore.addEventListener(Event.COMPLETE, oreCompleteHD);
			ore.start();

クラスの変更点としては、
・イベントの発行(dispatchEvent)ができるようにEventDispatcherのサブクラスとする
・Event.ENTER_FRAMEがEventDispatcherだと作動しなかったので仕方なくSpriteにした
・Mainでおこなっていた、ターゲットへのプロパティの適用をOreOreTweenでもつようにする
・start,pause,resumeのメソッド追加

という感じでしょうか。
自分で作ってみて驚いたのですが、イージングの定数部分をぬかした基本的なプログラム部分の行数は意外と短いです。

このままだと、インスタンスを生成するごとにEvent.ENTER_FRAMEを呼び出しちゃっているので、次回はそれをまとめるクラスを作ってみようと思います。
あと、delayの実装もしてなかったので、その辺もかな。

以下ソースです。

■OreOreTween

package  kuma_de
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	/**
	 * ...
	 * @author KinkumaDesign
	 */
	public class OreOreTween extends Sprite
	{
		//easing
		public static const EASE_NONE:String = "easeNone";
		public static const EASE_IN_QUAD:String = "easeInQuad";
		public static const EASE_OUT_QUAD:String = "easeOutQuad";
		public static const EASE_IN_OUT_QUAD:String = "easeInOutQuad";
		public static const EASE_OUT_IN_QUAD:String = "easeOutInQuad";
		public static const EASE_IN_CUBIC:String = "easeInCubic";
		public static const EASE_OUT_CUBIC:String = "easeOutCubic";
		public static const EASE_IN_OUT_CUBIC:String = "easeInOutCubic";
		public static const EASE_OUT_IN_CUBIC:String = "easeOutInCubic";
		public static const EASE_IN_QUART:String = "easeInQuart";
		public static const EASE_OUT_QUART:String = "easeOutQuart";
		public static const EASE_IN_OUT_QUART:String = "easeInOutQuart";
		public static const EASE_OUT_IN_QUART:String = "easeOutInQuart";
		public static const EASE_IN_QUINT:String = "easeInQuint";
		public static const EASE_OUT_QUINT:String = "easeOutQuint";
		public static const EASE_IN_OUT_QUINT:String = "easeInOutQuint";
		public static const EASE_OUT_IN_QUINT:String = "easeOutInQuint";
		public static const EASE_IN_SINE:String = "easeInSine";
		public static const EASE_OUT_SINE:String = "easeOutSine";
		public static const EASE_IN_OUT_SINE:String = "easeInOutSine";
		public static const EASE_OUT_IN_SINE:String = "easeOutInSine";
		public static const EASE_IN_EXPO:String = "easeInExpo";
		public static const EASE_OUT_EXPO:String = "easeOutExpo";
		public static const EASE_IN_OUT_EXPO:String = "easeInOutExpo";
		public static const EASE_OUT_IN_EXPO:String = "easeOutInExpo";
		public static const EASE_IN_CIRC:String = "easeInCirc";
		public static const EASE_OUT_CIRC:String = "easeOutCirc";
		public static const EASE_IN_OUT_CIRC:String = "easeInOutCirc";
		public static const EASE_OUT_IN_CIRC:String = "easeOutInCirc";
		public static const EASE_IN_ELASTIC:String = "easeInElastic";
		public static const EASE_OUT_ELASTIC:String = "easeOutElastic";
		public static const EASE_IN_OUT_ELASTIC:String = "easeInOutElastic";
		public static const EASE_OUT_IN_ELASTIC:String = "easeOutInElastic";
		public static const EASE_IN_BACK:String = "easeInBack";
		public static const EASE_OUT_BACK:String = "easeOutBack";
		public static const EASE_IN_OUT_BACK:String = "easeInOutBack";
		public static const EASE_OUT_IN_BACK:String = "easeOutInBack";
		public static const EASE_IN_BOUNCE:String = "easeInBounce";
		public static const EASE_OUT_BOUNCE:String = "easeOutBounce";
		public static const EASE_IN_OUT_BOUNCE:String = "easeInOutBounce";
		public static const EASE_OUT_IN_BOUNCE:String = "easeOutInBounce";
		
		
		private var _target:*;
		private var _tweenObjects:Object;
		private var _updateCount:int;
		private var _maxUpdateCount:int;
		private var _isTweening:Boolean;
		public function get isTweening():Boolean
		{
			return _isTweening;
		}
		
		
		public static function getTweenValues(to:Number, from:Number, duration:Number = 1.0, easing:String = EASE_NONE):Array
		{
			var frameRate:int = 30;//フレームレート
			
			var values:Array = [];
			var segmentNum:int = Math.floor(frameRate * duration); //分割数
			
			var i:int;
			var t:Number;
			var dt:Number = 1 / segmentNum;
			var time:Number;
			var value:Number;
			for (i = 0; i <= segmentNum; i++) {
				t = dt * i; //tは0以上1以下の範囲で動く
				time = t * duration; //開始からの時刻(秒)
				
				value = Equations[easing](time, from, to - from, duration);
				values.push(value); 
			}
			return values;
		}
		
		public function OreOreTween(target:*, to:Object, duration:Number = 1.0, easing:String = EASE_NONE, delay:Number = 0)
		{
			_isTweening = false;
			_tweenObjects = { };
			_target = target;
			
			for (var i:String in to) {
				_tweenObjects[i] = getTweenValues(to[i], target[i], duration, easing);
				_maxUpdateCount = _tweenObjects[i].length;
			}
		}
		
		public function start():void
		{
			if (!_isTweening) 
			{
				_isTweening = true;
				_updateCount = 0;
				addEventListener(Event.ENTER_FRAME, update);
			}
		}
		
		public function pause():void
		{
			if (_isTweening) 
			{
				removeEventListener(Event.ENTER_FRAME, update);
				_isTweening = false;
			}
		}
		
		public function reset():void
		{
			_updateCount = 0;
		}
		
		public function resume():void
		{
			if (!_isTweening) 
			{
				addEventListener(Event.ENTER_FRAME, update);
				_isTweening = true;
			}
		}
		
		private function update(e:Event):void 
		{
			//tween終了
			if (_updateCount == _maxUpdateCount) 
			{
				pause();
				dispatchEvent(new Event(Event.COMPLETE));
				
			//tween値を適用
			}else {
				var tweenValues:Array;
				var value:Number;
				for (var i:String in _tweenObjects) {
					_target[i] = _tweenObjects[i][_updateCount];
				}
				_updateCount++;
			}
		}
	}
}

■Main

package 
{
	import com.bit101.components.HSlider;
	import com.bit101.components.Label;
	import com.bit101.components.List;
	import com.bit101.components.PushButton;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import kuma_de.OreOreTween;
	
	/**
	 * ...
	 * @author KinkumaDesign
	 */
	[SWF(width="450",height="450",backgroundColor="0x000000",frameRate="30")]
	public class Main extends Sprite 
	{
		public var ball:Circle;
		public var startPos:Circle;
		public var endPos:Circle;
		public var startBtn:PushButton;
		public var easingList:List;
		public var durationSlider:HSlider;
		public var opacitySlider:HSlider;
		
		public var ore:OreOreTween;

		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			ball = new Circle(20, 0x1ECAE8);
			addChild(ball);
			ball.setPosition(50, 100);
			
			startPos = new Circle(10, 0xE91283, 1, true);
			addChild(startPos);
			startPos.setPosition(50, 100);
			
			endPos = new Circle(10, 0xE91283, 1, true);
			addChild(endPos);
			endPos.setPosition(400, 200);
			
			
			startBtn = new PushButton(this, 250, 380, "start", startBtnClickHD);
			
			var label:Label = new Label(this, 100, 280, "EASING");
			label.textField.textColor = 0xffffff;
			var easingListItem:Array = getEasingListItem();
			easingList = new List(this, 100, 300, easingListItem);
			easingList.selectedIndex = 1;
			
			label = new Label(this, 250, 280, "DULATION");
			label.textField.textColor = 0xffffff;
			
			durationSlider = new HSlider(this, 250, 300, null);
			durationSlider.maximum = 2.0;
			durationSlider.minimum = 0.1;
			durationSlider.tick = 0.1;
			durationSlider.value = 1.1;
			
			label = new Label(this, 250, 320, "OPACITY");
			label.textField.textColor = 0xffffff;
			opacitySlider = new HSlider(this, 250, 340, null);
			opacitySlider.maximum = 1.0;
			opacitySlider.minimum = 0;
			opacitySlider.tick = 0.01;
			opacitySlider.value = 0;
		}
		
		private function startBtnClickHD(e:MouseEvent):void
		{
			if (ore == null) {
				//初期位置へ
				ball.setPosition(startPos.x, startPos.y);
				ball.alpha = 1;
				
				var duration:Number = durationSlider.value;
				var easing:String = String(easingList.selectedItem);
				
				//使い方
				ore = new OreOreTween(ball, { 
					x:endPos.x,
					y:endPos.y,
					alpha:opacitySlider.value
					}, duration, easing);
				ore.addEventListener(Event.COMPLETE, oreCompleteHD);
				ore.start();
				
				startBtn.label = "PAUSE";
			}else if (ore.isTweening) {
				ore.pause();
				startBtn.label = "RESUME";
			}else if (!ore.isTweening) {
				ore.resume();
				startBtn.label = "PAUSE";
			}
		}
		
		private function oreCompleteHD(e:Event):void 
		{
			ore.removeEventListener(Event.COMPLETE, oreCompleteHD);
			ore = null;
			startBtn.label = "START";
		}
		
		private function getEasingListItem():Array
		{
			var ar:Array = [
			"easeNone",
			"easeInQuad",
			"easeOutQuad",
			"easeInOutQuad",
			"easeOutInQuad",
			"easeInCubic",
			"easeOutCubic",
			"easeInOutCubic",
			"easeOutInCubic",
			"easeInQuart",
			"easeOutQuart",
			"easeInOutQuart",
			"easeOutInQuart",
			"easeInQuint",
			"easeOutQuint",
			"easeInOutQuint",
			"easeOutInQuint",
			"easeInSine",
			"easeOutSine",
			"easeInOutSine",
			"easeOutInSine",
			"easeInExpo",
			"easeOutExpo",
			"easeInOutExpo",
			"easeOutInExpo",
			"easeInCirc",
			"easeOutCirc",
			"easeInOutCirc",
			"easeOutInCirc",
			"easeInElastic",
			"easeOutElastic",
			"easeInOutElastic",
			"easeOutInElastic",
			"easeInBack",
			"easeOutBack",
			"easeInOutBack",
			"easeOutInBack",
			"easeInBounce",
			"easeOutBounce",
			"easeInOutBounce",
			"easeOutInBounce"
			];
			return ar;
		}
	}
	
}

■Circle

package  
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	/**
	 * ...
	 * @author KinkumaDesign
	 */
	public class Circle extends Sprite
	{		
		public function Circle(radius:Number = 5, color:int = 0, alpha:Number = 1, draggable:Boolean = false) 
		{
			var g:Graphics = this.graphics;
			g.beginFill(color, alpha);
			g.drawCircle(0, 0, radius);
			g.endFill();
			
			if (draggable) 
			{
				addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHD);
				buttonMode = true;
			}
		}
		
		private function mouseDownHD(e:MouseEvent):void 
		{
			if (stage != null) 
			{
				stage.addEventListener(MouseEvent.MOUSE_UP, mouseUpHD);
				startDrag();
			}
		}
		
		private function mouseUpHD(e:MouseEvent):void 
		{
			stage.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHD);
			stopDrag();
		}
		
		public function setPosition(posX:Number, posY:Number):void
		{
			x = posX;
			y = posY;
		}
	}

}

■Equations

/*
Licensed under the MIT License

Copyright (c) 2006-2008 Zeh Fernando, Nate Chatellier, Arthur Debert and Francis
Turmel

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

http://code.google.com/p/tweener/
http://code.google.com/p/tweener/wiki/License

-------------------------------------------------------------------------------------

Disclaimer for Robert Penner's Easing Equations license:

TERMS OF USE - EASING EQUATIONS

Open source under the BSD License.

Copyright © 2001 Robert Penner
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

package  kuma_de
{
	/**
	 * ...
	 * @author KinkumaDesign
	 */
	public class Equations
	{

	// ==================================================================================================================================
	// TWEENING EQUATIONS functions -----------------------------------------------------------------------------------------------------
	// (the original equations are Robert Penner's work as mentioned on the disclaimer)
	// (the original code is from Tweener)

	// ==================================================================================================================================
	// TWEENING EQUATIONS functions -----------------------------------------------------------------------------------------------------
	// (the original equations are Robert Penner's work as mentioned on the disclaimer)

		/**
		 * Easing equation function for a simple linear tweening, with no easing.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeNone (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*t/d + b;
		}
	
		/**
		 * Easing equation function for a quadratic (t^2) easing in: accelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInQuad (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*(t/=d)*t + b;
		}
	
		/**
		 * Easing equation function for a quadratic (t^2) easing out: decelerating to zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutQuad (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return -c *(t/=d)*(t-2) + b;
		}
	
		/**
		 * Easing equation function for a quadratic (t^2) easing in/out: acceleration until halfway, then deceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutQuad (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d/2) < 1) return c/2*t*t + b;
			return -c/2 * ((--t)*(t-2) - 1) + b;
		}
	
		/**
		 * Easing equation function for a quadratic (t^2) easing out/in: deceleration until halfway, then acceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInQuad (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutQuad (t*2, b, c/2, d, p_params);
			return easeInQuad((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a cubic (t^3) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInCubic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*(t/=d)*t*t + b;
		}
	
		/**
		 * Easing equation function for a cubic (t^3) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutCubic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*((t=t/d-1)*t*t + 1) + b;
		}
	
		/**
		 * Easing equation function for a cubic (t^3) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutCubic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d/2) < 1) return c/2*t*t*t + b;
			return c/2*((t-=2)*t*t + 2) + b;
		}
	
		/**
		 * Easing equation function for a cubic (t^3) easing out/in: deceleration until halfway, then acceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInCubic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutCubic (t*2, b, c/2, d, p_params);
			return easeInCubic((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a quartic (t^4) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInQuart (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*(t/=d)*t*t*t + b;
		}
	
		/**
		 * Easing equation function for a quartic (t^4) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutQuart (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return -c * ((t=t/d-1)*t*t*t - 1) + b;
		}
	
		/**
		 * Easing equation function for a quartic (t^4) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutQuart (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
			return -c/2 * ((t-=2)*t*t*t - 2) + b;
		}
	
		/**
		 * Easing equation function for a quartic (t^4) easing out/in: deceleration until halfway, then acceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInQuart (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutQuart (t*2, b, c/2, d, p_params);
			return easeInQuart((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a quintic (t^5) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInQuint (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*(t/=d)*t*t*t*t + b;
		}
	
		/**
		 * Easing equation function for a quintic (t^5) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutQuint (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c*((t=t/d-1)*t*t*t*t + 1) + b;
		}
	
		/**
		 * Easing equation function for a quintic (t^5) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutQuint (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;
			return c/2*((t-=2)*t*t*t*t + 2) + b;
		}
	
		/**
		 * Easing equation function for a quintic (t^5) easing out/in: deceleration until halfway, then acceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInQuint (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutQuint (t*2, b, c/2, d, p_params);
			return easeInQuint((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a sinusoidal (sin(t)) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInSine (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
		}
	
		/**
		 * Easing equation function for a sinusoidal (sin(t)) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutSine (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c * Math.sin(t/d * (Math.PI/2)) + b;
		}
	
		/**
		 * Easing equation function for a sinusoidal (sin(t)) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutSine (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;
		}
	
		/**
		 * Easing equation function for a sinusoidal (sin(t)) easing out/in: deceleration until halfway, then acceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInSine (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutSine (t*2, b, c/2, d, p_params);
			return easeInSine((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for an exponential (2^t) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInExpo (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b - c * 0.001;
		}
	
		/**
		 * Easing equation function for an exponential (2^t) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutExpo (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return (t==d) ? b+c : c * 1.001 * (-Math.pow(2, -10 * t/d) + 1) + b;
		}
	
		/**
		 * Easing equation function for an exponential (2^t) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutExpo (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t==0) return b;
			if (t==d) return b+c;
			if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b - c * 0.0005;
			return c/2 * 1.0005 * (-Math.pow(2, -10 * --t) + 2) + b;
		}
	
		/**
		 * Easing equation function for an exponential (2^t) easing out/in: deceleration until halfway, then acceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInExpo (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutExpo (t*2, b, c/2, d, p_params);
			return easeInExpo((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a circular (sqrt(1-t^2)) easing in: accelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInCirc (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;
		}
	
		/**
		 * Easing equation function for a circular (sqrt(1-t^2)) easing out: decelerating from zero velocity.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutCirc (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c * Math.sqrt(1 - (t=t/d-1)*t) + b;
		}
	
		/**
		 * Easing equation function for a circular (sqrt(1-t^2)) easing in/out: acceleration until halfway, then deceleration.
 		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutCirc (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;
			return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;
		}
	
		/**
		 * Easing equation function for a circular (sqrt(1-t^2)) easing out/in: deceleration until halfway, then acceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInCirc (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutCirc (t*2, b, c/2, d, p_params);
			return easeInCirc((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for an elastic (exponentially decaying sine wave) easing in: accelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param a		Amplitude.
		 * @param p		Period.
		 * @return		The correct value.
		 */
		public static function easeInElastic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t==0) return b;
			if ((t/=d)==1) return b+c;
			var p:Number = !Boolean(p_params) || isNaN(p_params.period) ? d*.3 : p_params.period;
			var s:Number;
			var a:Number = !Boolean(p_params) || isNaN(p_params.amplitude) ? 0 : p_params.amplitude;
			if (!Boolean(a) || a < Math.abs(c)) {
				a = c;
				s = p/4;
			} else {
				s = p/(2*Math.PI) * Math.asin (c/a);
			}
			return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
		}
	
		/**
		 * Easing equation function for an elastic (exponentially decaying sine wave) easing out: decelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param a		Amplitude.
		 * @param p		Period.
		 * @return		The correct value.
		 */
		public static function easeOutElastic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t==0) return b;
			if ((t/=d)==1) return b+c;
			var p:Number = !Boolean(p_params) || isNaN(p_params.period) ? d*.3 : p_params.period;
			var s:Number;
			var a:Number = !Boolean(p_params) || isNaN(p_params.amplitude) ? 0 : p_params.amplitude;
			if (!Boolean(a) || a < Math.abs(c)) {
				a = c;
				s = p/4;
			} else {
				s = p/(2*Math.PI) * Math.asin (c/a);
			}
			return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);
		}
	
		/**
		 * Easing equation function for an elastic (exponentially decaying sine wave) easing in/out: acceleration until halfway, then deceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param a		Amplitude.
		 * @param p		Period.
		 * @return		The correct value.
		 */
		public static function easeInOutElastic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t==0) return b;
			if ((t/=d/2)==2) return b+c;
			var p:Number = !Boolean(p_params) || isNaN(p_params.period) ? d*(.3*1.5) : p_params.period;
			var s:Number;
			var a:Number = !Boolean(p_params) || isNaN(p_params.amplitude) ? 0 : p_params.amplitude;
			if (!Boolean(a) || a < Math.abs(c)) {
				a = c;
				s = p/4;
			} else {
				s = p/(2*Math.PI) * Math.asin (c/a);
			}
			if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;
			return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;
		}
	
		/**
		 * Easing equation function for an elastic (exponentially decaying sine wave) easing out/in: deceleration until halfway, then acceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param a		Amplitude.
		 * @param p		Period.
		 * @return		The correct value.
		 */
		public static function easeOutInElastic (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutElastic (t*2, b, c/2, d, p_params);
			return easeInElastic((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in: accelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param s		Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
		 * @return		The correct value.
		 */
		public static function easeInBack (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			var s:Number = !Boolean(p_params) || isNaN(p_params.overshoot) ? 1.70158 : p_params.overshoot;
			return c*(t/=d)*t*((s+1)*t - s) + b;
		}
	
		/**
		 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param s		Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
		 * @return		The correct value.
		 */
		public static function easeOutBack (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			var s:Number = !Boolean(p_params) || isNaN(p_params.overshoot) ? 1.70158 : p_params.overshoot;
			return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
		}
	
		/**
		 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing in/out: acceleration until halfway, then deceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param s		Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
		 * @return		The correct value.
		 */
		public static function easeInOutBack (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			var s:Number = !Boolean(p_params) || isNaN(p_params.overshoot) ? 1.70158 : p_params.overshoot;
			if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;
			return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;
		}
	
		/**
		 * Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out/in: deceleration until halfway, then acceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @param s		Overshoot ammount: higher s means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent).
		 * @return		The correct value.
		 */
		public static function easeOutInBack (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutBack (t*2, b, c/2, d, p_params);
			return easeInBack((t*2)-d, b+c/2, c/2, d, p_params);
		}
	
		/**
		 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in: accelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInBounce (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			return c - easeOutBounce (d-t, 0, c, d) + b;
		}
	
		/**
		 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out: decelerating from zero velocity.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutBounce (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if ((t/=d) < (1/2.75)) {
				return c*(7.5625*t*t) + b;
			} else if (t < (2/2.75)) {
				return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
			} else if (t < (2.5/2.75)) {
				return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
			} else {
				return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
			}
		}
	
		/**
		 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing in/out: acceleration until halfway, then deceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeInOutBounce (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeInBounce (t*2, 0, c, d) * .5 + b;
			else return easeOutBounce (t*2-d, 0, c, d) * .5 + c*.5 + b;
		}
	
		/**
		 * Easing equation function for a bounce (exponentially decaying parabolic bounce) easing out/in: deceleration until halfway, then acceleration.
		 *
		 * @param t		Current time (in frames or seconds).
		 * @param b		Starting value.
		 * @param c		Change needed in value.
		 * @param d		Expected easing duration (in frames or seconds).
		 * @return		The correct value.
		 */
		public static function easeOutInBounce (t:Number, b:Number, c:Number, d:Number, p_params:Object = null):Number {
			if (t < d/2) return easeOutBounce (t*2, b, c/2, d, p_params);
			return easeInBounce((t*2)-d, b+c/2, c/2, d, p_params);
		}
	}

}

自作iPhoneアプリ 好評発売中!
フォルメモ - シンプルなフォルダつきメモ帳
ジッピー電卓 - 消費税や割引もサクサク計算!

ページトップへ戻る