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

frocessing test

// forked from nutsu's forked from: code on 2008-12-17
// forked from nutsu's code on 2008-12-17
// write as3 code here..
package 
{
	import flash.display.*;
	import flash.events.*;
        import frocessing.core.*;
        import frocessing.f3d.models.*;
        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;
		
                private var bmg:F5BitmapData2D;
                private var sss:F3DSphere;

		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();
                        
                        bmg = new F5BitmapData2D(_w,_h,false,0);
                        bmg.curveDetail(5);
                        
                        sss = new F3DSphere(100);
                        sss.setTexture( bmg.bitmapData );
                        
		}
		
		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);
			
                        bmg.beginDraw();
                        bmg.noStroke();
                        
                        bmg.fill(0,0.05);
                        bmg.rect(0,0,_w,_h);
			bmg.fill(255);
                        
                        bmg.translate(_w/2, _h/2);
                        bmg.beginShape();
			var wp:WavePoint = WavePoint( _P[_n - 1] );
			bmg.curveVertex( wp.x, wp.y );
			for ( var i:int = 0; i<_n; i++ )
			{
				wp = WavePoint( _P[i] );
				bmg.curveVertex( wp.x, wp.y );
			}
                        wp = WavePoint( _P[0] );
                        bmg.curveVertex( wp.x, wp.y );
			bmg.endShape();
                        bmg.endDraw();
                        
                        translate(_w/2, _h/2);
                        rotateX(raa);
                        rotateY(raa*0.5);
                        stroke(127);
                        model(sss);

                        raa+=0.02;
		}
	}
}

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;
	}
}