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

新しいeditorを試す

Get Adobe Flash player
by knd 14 Dec 2009
package {
	import flash.events.Event;
    import flash.display.Sprite;
    import flash.geom.Point;
    public class FlashTest extends Sprite {
    		private const A:Number = 0.8; //(+0, +1)
    		private const D:Number = 0.02; //(+0, )
    		private const F:Number = 0.95; //(-1, +1)
    		
    		private const C:Number = 2 + D - 2 * A;
    		private const K:Number = 1 / (1 + D);
    		private const E:Number = A * (1 + F);
    		
    		private const N:uint = 120;
    		private const H:Number = 465.0;
    		private const Y0:Number = 288.;
    		private const R:Number = H / 2 / N;
    		
    		private var currX:Vector.<Number> = new Vector.<Number>();
    		private var currY:Vector.<Number> = new Vector.<Number>();
    		private var prevY:Vector.<Number> = new Vector.<Number>();
    		private var nextY:Vector.<Number> = new Vector.<Number>();
        public function FlashTest() {
            // write as3 code here..
            this.y = Y0;
            for(var i:uint = 0;  i<= N; i++)
            {
            		currX[i] = H * i / N;
            		prevY[i] = 0;
            		currY[i] = 0; 
            }
            this.addEventListener("enterFrame", loop);
            stage.addEventListener("mouseMove", move);
        }
        private function move(evt:Event):void
        {
        		var pos:uint = (stage.mouseX / H * N)| 0;
        		currY[pos] += (stage.mouseY - Y0) > currY[pos]? -1: 1;
        }
        private function loop(evt:Event):void
        {
        		var i:uint;
        		nextY = new Vector.<Number>();
        		nextY[0] = K * ( C * currY[0] - prevY[0] + E * currY[1]);
		    for(i = 1;  i< N; i++)
		    {
		    		nextY[i] = K * ( C * currY[i] - prevY[i] + A * (currY[i+1] + currY[i-1]));
		    }
		    nextY[N] = K * ( C * currY[N] - prevY[N] + E * currY[N-1]);
        		prevY = currY;
        		currY = nextY;
        		
        		this.graphics.clear();
        		this.graphics.beginFill(0x333355);
        		var pt:Point;
            for(i = 0;  i<= N; i++)
            {
            		this.graphics.drawCircle(currX[i], currY[i], R);
            }
        		
        }
    }
}