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: 新しいeditorを試す

Get Adobe Flash player
by knd 14 Dec 2009
// forked from knd's 新しいeditorを試す
package {
	import flash.events.Event;
    import flash.display.Sprite;
    import flash.geom.Point;
    public class FlashTest extends Sprite {
    		private const A:Number = 0.16; //波の速度の二乗 (+0, +1)
    		private const D:Number = 0.03; //減衰係数(+0, )
    		private const F:Number = 0.75; //反射係数(-1, +1)
    		
    		//よく使う形にまとめる
    		private const C:Number = 2 + D - 4 * A;
    		private const K:Number = 1 / (1 + D);
    		private const E:Number = A * (1 + F);
    		
    		private const N:uint = 40; //円の数
    		private const H:Number = 465.0; //
    		private const P:Number = H / N; //繰り返し間隔
    		private const _P:Number = 1 / P; //間隔の逆数
    		private const R:Number = P / 2.8; //円の半径
    		
   		private var currY:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>();
    		private var prevY:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>();
    		private var nextY:Vector.<Vector.<Number>> = new Vector.<Vector.<Number>>();
    		
        public function FlashTest() {
            // write as3 code here..
            for(var i:uint = 0;  i<= N; i++)
            {
            		currY[i] = new Vector.<Number>();
            		prevY[i] = new Vector.<Number>();
            		nextY[i] = new Vector.<Number>();
	            for(var j:uint = 0;  j<= N; j++)
	            {
	            		prevY[i][j] = 0;
	            		currY[i][j] = 0; 
	            		nextY[i][j] = 0; 
	            }
            }
            this.addEventListener("enterFrame", loop);
            stage.addEventListener("mouseMove", move);
        }
        private function move(evt:Event):void
        {
        		var posX:uint = (stage.mouseX * _P)| 0;
        		var posY:uint = (stage.mouseY * _P)| 0;
        		currY[posX][posY] += 1;
        }
        private function loop(evt:Event):void
        {
        		var i:uint, j:uint;
        		//左上角
			nextY[0][0] = K * ( C * currY[0][0] - prevY[0][0] + E * (currY[0][1] + currY[1][0]));
 	    		for(j = 1; j< N; j++)
	    		{
	    			//上境界
		    		nextY[0][j] = K * ( C * currY[0][j] - prevY[0][j] + A * (currY[0][j+1] + currY[0][j-1]) + E * currY[1][j]);
	    		}
	    		//右上角
			nextY[0][N] = K * ( C * currY[0][N] - prevY[0][N] + E * (currY[0][N-1] + currY[1][N]));
		    for(i = 1;  i< N; i++)
		    {
		    		//左境界
		    		nextY[i][0] = K * ( C * currY[i][0] - prevY[i][0] + A * (currY[i+1][0] + currY[i-1][0]) + E * currY[i][1]);
		    		for(j = 1; j< N; j++)
		    		{
		    			//境界より内側
			    		nextY[i][j] = K * ( C * currY[i][j] - prevY[i][j] + A * (currY[i+1][j] + currY[i-1][j] + currY[i][j+1] + currY[i][j-1]));
		    		}
		    		//右境界
		    		nextY[i][N] = K * ( C * currY[i][N] - prevY[i][N] + A * (currY[i+1][N] + currY[i-1][N]) + E * currY[i][N-1]);
		    }
		    //左下角
 			nextY[N][0] = K * ( C * currY[N][0] - prevY[N][0] + E * (currY[N][1] + currY[N-1][0]));
 	    		for(j = 1; j< N; j++)
	    		{
	    			//下境界
		    		nextY[N][j] = K * ( C * currY[N][j] - prevY[N][j] + A * (currY[N][j+1] + currY[N][j-1]) + E * currY[N-1][j]);
	    		}
	    		//右下角
			nextY[N][N] = K * ( C * currY[N][N] - prevY[N][N] + E * (currY[N][N-1] + currY[N-1][N]));
      				    
        		this.graphics.clear();
        		var pt:Point;
            for(i = 0;  i<= N; i++)
            {
 		    		for(j = 0; j<= N; j++)
		    		{
		    			prevY[i][j] = currY[i][j];
		    			currY[i][j] = nextY[i][j];
    			    		this.graphics.beginFill(0x0, (currY[i][j] + 3)/6);
  	         		this.graphics.drawCircle(P * i, P * j - currY[i][j], R);
		    		}
            }
        		
        }
    }
}