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: code on 2008-12-17

Get Adobe Flash player
by nutsu 18 Dec 2008
// forked from nutsu's code on 2008-12-17
// write as3 code here..
package 
{
	import flash.display.*;
	import flash.events.*;
        import frocessing.display.*;
	
	[SWF(frameRate="30", backgroundColor="#000000")] 
	public class WaveSimp extends F5MovieClip3D
	{
		
		private var _w:Number;
		private var _h:Number;
		private var px:Number;
		private var py:Number;
		
		private var _P:Array;
		private var _n:int = 20;
		
		public function WaveSimp() 
		{
			_w = stage.stageWidth;
			_h = stage.stageHeight;
			
			_P = [];
			var delta:Number = TWO_PI/_n;
			for ( var n:int = 0; n<_n; n++ )
				_P[n] = new WavePoint( _w/4, Math.cos(delta * n), Math.sin(delta * n) );
			
			px = mouseX;
			py = mouseY;
			
			stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove );
			
			QMedium();

                        curveDetail(5);
		}
		
		private function mouseMove( e:MouseEvent ):void
		{
			px = ( mouseX - px ) * 0.15;
			py = ( mouseY - py ) * 0.15;
			_P[0].a += mag( px , py );
			px = mouseX;
			py = mouseY;
		}
		
		private function cal(ps:Array):void
		{
			var i:int;
			
			var wp0:WavePoint = WavePoint(ps[_n-1]);
			var wp:WavePoint  = WavePoint(ps[0]);
			var wp1:WavePoint = WavePoint(ps[1]);
			calAccel( wp0, wp, wp1 );
			
			wp0 = wp;
			wp  = wp1;
			for ( i = 1; i < _n-1; i++ )
			{
				wp1 = WavePoint(ps[i+1]);
				calAccel( wp0, wp, wp1 );
				wp0 = wp;
				wp  = wp1;
			}
			calAccel( wp0, wp, WavePoint(ps[0]) );
			
			for ( i = 0; i < _n; i++ )
			{
				wp = WavePoint(ps[i]);
				wp.vr += wp.a;
				wp.a *= 0.98;
			}
		}
		
		private function calAccel( wp0:WavePoint, wp:WavePoint, wp1:WavePoint ):void
		{
			var pv:Number = ( wp0.vr + wp1.vr - 4*wp.vr )*0.1;
			wp.a += pv;
			wp1.a += -pv*0.4;
			wp0.a += -pv*0.4;
		}
		

                private var raa:Number = 0;
                
		public function draw():void
		{
			cal(_P);
			
                        noStroke();
			fill(255);
                        
                        translate(_w/2, _h/2);
                        rotateX(raa);
                        rotateY(raa*0.);
                        beginShape();
			var wp:WavePoint = WavePoint( _P[_n - 1] );
			curveVertex( wp.x, wp.y );
			for ( var i:int = 0; i<_n; i++ )
			{
				wp = WavePoint( _P[i] );
				curveVertex( wp.x, wp.y );
			}
                        wp = WavePoint( _P[0] );
                        curveVertex( wp.x, wp.y );
			endShape();
                        
                        raa+=0.01;
		}
	}
}

class WavePoint 
{
	public var r:Number;
	public var vr:Number;
	public var vx:Number;
	public var vy:Number;
	public var a:Number;
	
	public function WavePoint( r:Number, vx:Number, vy:Number ) 
	{
		this.r   = r;
		this.vr  = 0;
		this.vx  = vx;
		this.vy  = vy;
		a = 0;
	}
	
	public function get x():Number
	{
		return (vr + r) * vx;
	}
	
	public function get y():Number
	{
		return (vr + r) * vy;
	}
}