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 matsu4512 05 Mar 2009
package {
	import flash.display.Sprite;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	[SWF(backgroundColor = "#000000")]
	public class hirahira extends Sprite
	{
		private var ary:Array;
		private var pos:Array;
		private const NUM:uint = 100;
		private const SIZE:uint = 3;
		public function hirahira()
		{
			ary = new Array();
			pos = new Array();
			for(var i:uint = 0; i < NUM; i++){
				ary[i] = new Sprite();
				ary[i].graphics.clear();
				ary[i].graphics.beginFill(Math.random() * 0xFFFFFF);
				ary[i].graphics.lineStyle(0, 0, 0);
				ary[i].graphics.drawRect(0, 0, SIZE, SIZE);
				ary[i].graphics.endFill();
				addChild(ary[i]);
				pos[i] = new PhysicalPoint(stage.stageWidth/4, stage.stageHeight/4);
			}
			
			var timer:Timer = new Timer(33);
			timer.addEventListener(TimerEvent.TIMER, loop);
			timer.start();
		}
		
		private function loop(event:TimerEvent):void{
			//各ピースの位置の計算
			for(var i:Number = 0; i < ary.length; i++){
					pos[i].setKasokudoByPolar(Math.random() * 1000, Math.random()*Math.PI*2);
					var dist:Number = Point.distance(pos[i], new Point(mouseX, mouseY));
					var dire:Number = Math.atan2(mouseY - pos[i].y, mouseX - pos[i].x);
					pos[i].setKasokudoByPolar(dist*5*Math.random(), dire);
			}
			
			//各ピースの位置、大きさの設定、動きをつけるためにランダムに大きさを指定
			for(i = 0; i < ary.length; i++){
					ary[i].x = pos[i].x;
					ary[i].y = pos[i].y;
					ary[i].scaleX = Math.random();
					ary[i].scaleY = Math.random();
			}
		}
	}
}

         import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.geom.Point;

	class PhysicalPoint extends Point{
    	public var vx:Number, vy:Number;
    	private var ax:Number, ay:Number;
    	public var b:Number;
    	public var sakkiTime:Number;
    	public var timer:Timer;
    
    	public function PhysicalPoint(xx: Number=0, yy: Number=0){
      		x = xx;      
      		y = yy;
      		b = 0.9;
      		vx = 0;      
      		vy = 0;
      		ax = 0;      
      		ay = 0;
      		
      		sakkiTime = new Date().getTime();
      
      		timer = new Timer(33);
      		timer.addEventListener(TimerEvent.TIMER, loop);
      		timer.start();
    	}

    	private function loop(event:TimerEvent):void{
      		var nowTime:Number = new Date().getTime();
      		var t:Number = (nowTime - sakkiTime)/1000;
      
      		x += vx*t + 0.5*ax*t*t;
      		y += vy*t + 0.5*ay*t*t;
      
      		vx += ax*t;
      		vy += ay*t;
      
      		vx *= b;
      		vy *= b;
      
      		ax = 0;
      		ay = 0;
      
      		sakkiTime = nowTime;
    	}
    
    	public function setKasokudo(aax:Number=0, aay:Number=0):void{
      		ax += aax;
      		ay += aay;
    	}
    
    	public function setKasokudoByPolar(r:Number=0, dire:Number=0):void{
      		ax += r*Math.cos(dire);
      		ay += r*Math.sin(dire);
    	}
  	}