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

plasma

Get Adobe Flash player
by hacker_3szp8277 31 Dec 2008
    Embed
package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;

	public class Plasma3 extends Sprite
	{
		
		private var canvas:BitmapData;
		private var offscreen:BitmapData;
		private var palette:Array=new Array;//256
		private var table:Array=new Array;//512
		private const WIDTH:int=120;
		private const HEIGHT:int=120;
		private var phaseA:Number=0;
		private var phaseB:Number=0;
		
		private const factor1:Number = -2;
		private const factor2:Number = -1;
		private const factor3:Number = 1;
		private const factor4:Number = -2;
		
		private var red:Number = 500.0;
		private var green:Number = 128.0;//320.0;
		private var blue:Number = 60.0;//372.0;
		
		private var scale1:Number = 2.0;
		private var scale2:Number = 127.5;
		private var scale3:Number = 256; 
		public function Plasma3()
		{
			initPlasma();
			addEventListener(Event.ENTER_FRAME,move);
			
			canvas = new BitmapData(WIDTH,HEIGHT,false,0);
			graphics.beginBitmapFill(canvas);
			graphics.drawRect(0,0,480,480);
			graphics.endFill();

		}
		
		private function move(e:Event):void{
			DrawPlasma(width);	
		}



		/*
		;-----------------------------------------------------------;
		;                Calculate Next Plasma Frame                ;
		;-----------------------------------------------------------;
		;色のゆれる様を計算
		*/
		
		const pt:Point = new Point;
		private function DrawPlasma(pitch:Number){
			var pixel:int = 0;
			var pa:Number = 0xff&phaseA;
			var pb:Number = 0xff&phaseB;
                            canvas.lock();
			for(var i=0;i<HEIGHT;i++){
				for(var j=0;j<WIDTH;j++){
					var t1:int = (j+table[pa+i])&0xff;
					var t2:int = (i+table[pb])&0xff;
					var val3:int = table[t1]+factor3;
					var val4:int = table[t2+256]+factor4;
					var idx:int = ((val3+val4)/2)&0xff
					canvas.setPixel(i,j,palette[idx]);
				}
			}
			phaseA += factor1;
			phaseB += factor2;
			canvas.unlock();
		}
		/*
		;-----------------------------------------------------------;
		;                Initalize Plasma Tables                    ;
		;-----------------------------------------------------------;
		*/

		private function initPlasma(){
			var i:int = 0;
			while(i<256){
				var v:Number;
				v = Math.sin(Math.PI*i*scale1/scale3)*scale2+scale2;
				table[i] = int(v);
				//trace("table["+i+"]="+int(table[i]).toString(16));
				/*
				; Calculate table1 value
				*/
				v = Math.cos(Math.PI*i*scale1/scale3)*scale2+scale2;
				var v2 = Math.sin(Math.PI*v*scale1/scale3)*scale2+scale2;
				table[i+256]=int(v2);
				//trace("table["+(i+256)+"]="+int(table[i+256]).toString(16));
				/*			
				; Calculate palette value
				;パレット値を算出
				*/	
				const col:Array = [red,green,blue];
				var ret:int = 0;
				for(var k=0;k<3;k++){
					var seed:Number = (Math.PI*i*scale1/col[k]);
					v = Math.cos(seed)*scale2+scale2;
					var temp:int = int(v);
					//ret = ;
					ret = (ret<<8)|temp;
				}
				palette[i]=ret;
			 	i++;
			}
		}
	}
}