In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

適当にうろうろする

Get Adobe Flash player
by HaraMakoto 29 Aug 2009
/**
 * Copyright HaraMakoto ( http://wonderfl.net/user/HaraMakoto )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/d07f
 */

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.utils.Timer;

	[SWF(width="465", height="465", backgroundColor="0x0", frameRate="30")]
	public class RandomWalkTest extends Sprite
	{
		public var vx:Number=10;
		public var vy:Number=10;
		public var _x:Number=0;
		public var _y:Number=0;
		private var ax:Number=0;
		private var ay:Number=0;
		
		private var angle:Number=0;
		private var AngleTarget:Number = 0;
		private var R:Number=10;
		public var counter:int=0;
		
		private var ac:Number = 0.45;
    	        private var de:Number = 0.96;
		
		private var ox:Number=0;
		private var oy:Number=0;
		
		private var targetVx:Number=0;
		private var targetVy:Number=0;
		private var targetX:Number=0;
		private var targetY:Number=0;
		
		private var bmp:Bitmap = new Bitmap();
		private var bmd:BitmapData
		
		//mova
		private var mova:Sprite = new Sprite();
		
		
		//timer
		private var timer:Timer = new Timer(3000);
		
		public function RandomWalkTest()
		{
			addChild(bmp);
			addChild(mova);
			makeCirCle();
			bmd = new BitmapData(465,465,false,0x000000);
	      	        bmp.bitmapData = bmd;
	      	        addEventListener(Event.ENTER_FRAME, handleEnterFrame);
		 	timer.addEventListener(TimerEvent.TIMER, timerHandler);
	      	        timer.start();
	      	        timerHandler(null);
		}
		private function timerHandler(e:TimerEvent):void {
			AngleTarget = -60 + 120 * Math.random();
			R=20*Math.random();
		}
		private function makeCirCle():void {
			mova.graphics.beginFill(0xFFFFFF);
			mova.graphics.drawCircle(0,0,2);
			mova.graphics.endFill();
		}
		public function handleEnterFrame(e:Event):void
		{
			targetVx = R * Math.cos(angle*Math.PI/180);
			targetVy = R * Math.sin(angle*Math.PI/180);
			
			targetX += targetVx;
			targetY += targetVy;
			
			ax = (targetX - ox)*ac;
			ay = (targetY - oy)*ac;
			vx += ax;
			vy += ay;
			
			_x += vx;
			_y += vy;
			
			mova.x = _x;
			mova.y = _y;
			
			angle += 0.5*(AngleTarget - angle);
			
			counter++;
			
			if(targetX > 465) {targetX=0;_x=0;}
			if(targetX< 0) {targetX = 465;_x=465;}
			if(targetY > 465) {targetY=0;_y=0;}
			if(targetY < 0) {targetY = 465;_y=465;}
			
			vx *= de;
			vy *= de;
			
			ox = _x;
			oy = _y;
			
			bmd.setPixel(_x, _y, 0xFFFFFF);
		}
	}
}