「Flex/parabola」の編集履歴(バックアップ)一覧に戻る

Flex/parabola - (2015/01/21 (水) 17:15:00) のソース

|開発環境|Apache [[Flex]] SDK 4.13.0|
||FlashDevelop 4.7.1.1|
|実行環境|Microsoft Windows 8.1 (64bit)|
|プロジェクトの種類|ActionScript 3/AS3 Project|
|プロジェクト名|parabola|
#table_zebra(project, #fff, #eee)

http://www.maroon.dti.ne.jp/lance/flash/parabola.html

Main.as
#highlight(actionscript){{
package
{
	import flash.display.Graphics;
	import flash.display.Sprite;
	import flash.events.Event;
	import mx.utils.StringUtil;
	
	public class Main extends Sprite 
	{
		
		public function Main() 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			
			var canvas:Sprite = new Sprite;
			var gr:Graphics = canvas.graphics;
			addChild(canvas);
			
			// 補助線
			gr.lineStyle(1, 0x000000);
			gr.moveTo(0, 0);
			gr.lineTo(0, 480);
			gr.lineTo(640, 480);
			
			const g:Number = 9.8; // 重力加速度 m/s^2
			const v0:Number = 30; // 初速 30m/s = 108km/h
			const th:Number = 45 * Math.PI / 180; // 角度
			const p:Number = 5; // 倍率
			const vx:Number = v0 * Math.cos(th);
			const vy:Number = v0 * Math.sin(th);

			gr.lineStyle(1, 0xff0000);
			gr.moveTo(0, 480);
			for (var t:Number = 0; ; t += 0.1) 
			{
				var x:Number = vx * t;
				var y:Number = vy * t - g * t * t / 2;
				trace(StringUtil.substitute("t:{0} x:{1} y:{2}", t, x, y));
				if (y < 0) break;
				gr.lineTo(x * p, 480 - y * p);
			}
		}
		
	}
	
}
}}