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

forked from: マウスから逃げる

マウスから逃げます。
// forked from sake's マウスから逃げる
/*
    マウスから逃げます。
*/

package
{
	import flash.display.BlendMode;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filters.GlowFilter;

	[SWF(width="465", height="465", backgroundColor="0x000000", frameRate="40")]

	public class RunAwayFromMouse extends Sprite
	{
		private var num:int=500;
		private var firstPointX:Array=new Array();
		private var firstPointY:Array=new Array();

		public function RunAwayFromMouse()
		{
			for(var i:int=0; i < num; i++)
			{
				var circle:Shape=new Shape();
                                var color:int = Math.random() * 0xFFFFFF;
                                var size:int = 10 + (Math.random() * 25);
                                
				//circle.graphics.beginFill(color);
                                circle.graphics.lineStyle(1, color);
				circle.graphics.moveTo(size * 0.5, 0);
				circle.graphics.lineTo(size, size);
				circle.graphics.lineTo(0, size * 0.3);
				circle.graphics.lineTo(size, size * 0.3);
				circle.graphics.lineTo(0, size);
				circle.graphics.lineTo(size * 0.5, 0);
				//circle.graphics.endFill();
				circle.blendMode=BlendMode.ADD;
                                circle.alpha = (size - 10) / 15;

				circle.x=Math.round(Math.random() * stage.stageWidth);
				circle.y=Math.round(Math.random() * stage.stageHeight);
				circle.name="circle" + i.toString();
				circle.filters=[new GlowFilter(color, 0.9, 8, 8, 2)];
				addChild(circle);

				firstPointX[i]=circle.x;
				firstPointY[i]=circle.y;
			}

			addEventListener(Event.ENTER_FRAME, onFrame);
		}


		public function onFrame(e:Event):void
		{
			for(var i:int=0; i < num; i++)
			{
				var circle:Shape=getChildByName("circle" + i.toString())as Shape;
				var theta:Number=Math.atan2(circle.y - mouseY, circle.x - mouseX);
				var d:Number=1000 / Math.sqrt(Math.pow(mouseX - circle.x, 2) + Math.pow(mouseY - circle.y, 2));

				circle.x+=d * Math.cos(theta) + (firstPointX[i] - circle.x) * 0.1;
				circle.y+=d * Math.sin(theta) + (firstPointY[i] - circle.y) * 0.1;
			}
		}
	}
}