forked from: 城戸さんのFlashセミナーの復習 サインカーブ

by hacker_szoe51ih
こないだのFlashセミナーの復習
サインカーブ
@author dory
♥0 | Line 69 | Modified 2010-06-13 23:26:18 | MIT License
play

ActionScript3 source code

/**
 * Copyright hacker_szoe51ih ( http://wonderfl.net/user/hacker_szoe51ih )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zdLR
 */

// forked from dory's 城戸さんのFlashセミナーの復習 サインカーブ
package 
{
	import flash.display.Sprite;
	import flash.events.Event;

	/**
	 * こないだのFlashセミナーの復習
	 * サインカーブ
	 * @author dory
	 */
	public class Main extends Sprite 
	{
		private const PI2:Number = Math.PI * 0.5;
		private const HITTING_TIME:Number = 4300;
		private const SPEED:Number =25;
		private var start:Circle;
		private var goal:Circle;

		private var circle:Circle;

		private var num:Number = 0;
		
		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);

			createCircles();
			
			addEventListener(Event.ENTER_FRAME, enterFrameHandler);
		}

		private function enterFrameHandler(event:Event):void {
			var mX:Number = goal.x - start.x;
			var mY:Number = goal.y - start.y;
			goal.y -= 2;
			circle.x = mX * (Math.sin(Math.PI * num / HITTING_TIME - PI2) + 1)*0.8  + start.x;
			circle.y = mY * (Math.sin(Math.PI * num / HITTING_TIME - PI2) + 1)*0.8  + start.y;
			
			num += SPEED;
			if( num > HITTING_TIME ){
				num = 0;
				goal.y = Math.random() * 300 + 300;
			}
		}

		private function createCircles():void {
			start = new Circle();
			start.x = 50;
			start.y = 100;
			addChild(start);

			goal = new Circle();
			goal.x = 400;
			goal.y = 300;
			addChild(goal);

			circle = new Circle(0xffff00);
			circle.x = 0;
			circle.y = 0;
			addChild(circle);
		}
		
	}

}

	import flash.display.Sprite;
	
	/**
	 * サークル
	 * @author Yoshimura Miho
	 */
	class Circle extends Sprite
	{
		private var _color:uint;
		
		public var angle:Number;
		public var distance:Number;
		
		public function Circle(color:uint = 0xff8000) 
		{
			_color = color;
			drawCircle();
		}
		
		private function drawCircle():void {
			graphics.beginFill(_color);
			graphics.drawCircle(0, 0, 20);
			graphics.endFill();
		}
		
	}