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 toni's 波を動かしてみる
package  
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.TimerEvent;
	import flash.utils.Timer;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import com.flashdynamix.utils.SWFProfiler;
	
	public class Main extends Sprite {
		private var pointNum:Number;
                private var pointSpeed:Number;
                private var pointSpeedDisorder:Number;
		private var lineFallSpeed :Number;
		private var point : Array;
                private var anchor : Array;
		private var rs : Number;
		private var gs : Number;
		private var bs : Number;
		private var ra : Number;
		private var ga : Number;
		private var ba : Number;
		private var lcount : Number;
		private var lmax : Number;
		private var colorArea : Number;
		private var waveInc : Boolean;
		private var waveRate : Number;
		private var waveLineRate : Number;
		private var waveMax : Number;
		private var waveSizeBase:Number;
		private var lineArray:Array;
		private var rFlag:int;
		private var line_mc:MySprite;
		private var stageH:Number;
		private var stageW:Number;
		
			
		/************************************************************************
		* おとす
		* ステージサイズを大きくするとかなり重くなる。。。。
		************************************************************************/
		public function Main(){
			addEventListener(Event.ADDED_TO_STAGE, onStage);
		}
		
		private function onStage(e:Event):void 
		{
			rFlag = 0;
			pointNum = 20;
			lineFallSpeed = 0.2;
			pointSpeed = 0.1;
			pointSpeedDisorder = 0.01;
			waveSizeBase = 80;
			colorArea = 40;
			stageH = stage.stageHeight;
			stageW = stage.stageWidth;
			
			/************************************************************************
			* ステージの設定
			************************************************************************/
			SWFProfiler.init(this);
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			lmax = 60;
			waveRate = 1;
			waveLineRate = 1;
			lcount = 0;
			
			
			
			/************************************************************************
			* 曲線
			************************************************************************/
			
			point = new Array();
			anchor = new Array();
			var i1:Number = -1;
			var xb:Number = stageW/(pointNum-1);
			var len:Number = pointNum;
			
			while (++i1 < len) {
				
				point[i1] = {
					x : i1*xb,
					angle : Math.random()*Math.PI*2,
					speed : Math.random()*pointSpeed,
					waveSize : Math.random() * waveSizeBase + 20
				};
				if(i1>0){
					anchor[i1-1] = new Object();
					anchor[i1-1] = {
						x : Math.floor((point[i1].x + point[i1 - 1].x) / 2)
					};
				}
				
			}
			
			/************************************************************************
			* 色の設定
			************************************************************************/
			rs = Math.random()*(Math.PI/180)*10;
			gs = Math.random()*(Math.PI/180)*10;
			bs = Math.random()*(Math.PI/180)*10;
			ra = ga = ba =0.1;
			i1 = lmax + 1;
			lineArray = [];
			
			addEventListener(Event.ENTER_FRAME, main);
			
		}
		
		
		/************************************************************************
		* ループ
		************************************************************************/
		private function main(e:Event):void {
			adjPoint();
			drawLine();		
		}

		/************************************************************************
		* 線の動き
		************************************************************************/
		private function adjPoint():void{
			var len:Number = pointNum;
			var i1:Number = -1;
			while (++i1<len) {
				//angleを設定
				point[i1].speed += Math.random()*pointSpeedDisorder*2 -pointSpeedDisorder;
				if(Math.abs(point[i1].speed)>pointSpeed) {
					point[i1].speed *= 0.9;
				}
				point[i1].angle += point[i1].speed;
				//曲線を描くための点の情報を設定
				point[i1].y = Math.sin(point[i1].angle) * point[i1].waveSize * waveRate;
				if(i1>0){
					anchor[i1 - 1].y = Math.floor((point[i1].y + point[i1 - 1].y) / 2);
				}
				
			}		
		}
		
		/************************************************************************
		* 曲線の描画
		************************************************************************/
		private function drawLine():void{
			line_mc = new MySprite();
			//addChild(line_mc);
			//線の色を設定
			line_mc.graphics.lineStyle(1, setColor(colorArea), 1);
			//線を描く
			line_mc.graphics.moveTo(point[0].x, point[0].y);
			var i1:Number = -1;
			var len:Number = pointNum-1;
			while(++i1 < len){
				line_mc.graphics.curveTo(point[i1].x, point[i1].y, anchor[i1].x, anchor[i1].y);
			}
			line_mc.graphics.curveTo(anchor[len-1].x, anchor[len-1].y, point[i1].x, point[i1].y);
			
			//線のプロパティを設定
			line_mc.sp = 1;
			line_mc.y = stageH/2;
			line_mc.alpha = 0.3;
			line_mc.visible = true;
			//線に落下させる動きをつける
			line_mc.addEventListener(Event.ENTER_FRAME, mov);
			//line_mc.addEventListener(Event.ADDED_TO_STAGE, mov);
			addChild(line_mc);
		}
		
		
		/************************************************************************
		* 色の変化
		************************************************************************/
		private function setColor(area:Number):Number{
			ra += rs;
			ga += gs;
			ba += bs;
			var r:Number = area+Math.cos(ra)*area;
			var g:Number = area+Math.cos(ga)*area;
			var b:Number = area+Math.cos(ba)*area;
			return (r << 16 | g << 8 | b);
		}
		
		/************************************************************************
		* 移動
		************************************************************************/
		private function mov(e:Event):void {
				if(e.target.sp < 30){
					e.target.sp += lineFallSpeed*waveLineRate;
					e.target.y += e.target.sp;
					e.target.alpha += 0.01;
					if(e.target.y>stageH+100){
						e.target.removeEventListener(Event.ENTER_FRAME, mov);
						removeChild(MySprite(e.target));
					};
				}else {
					e.target.removeEventListener(Event.ENTER_FRAME, mov);
					removeChild(MySprite(e.target));
				}
		}

	}

}


import flash.display.Sprite;

class MySprite extends Sprite
{
	
	public var sp:Number = 1;
	
	public function MySprite() 
	{
		
	}
	
}