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

camera of undefined

@autoher : muraken (undefined Inc.)
// @autoher : muraken (undefined Inc.)

package {
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.BitmapDataChannel;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Matrix;
	import flash.geom.Point;
	import flash.geom.Rectangle;
        import flash.media.Camera;
	import flash.media.Video;
	[SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="40")]
	public class NoiseDisplay extends Sprite {
		private var bmp:Bitmap;
		private const BMD_WIDTH:int = 240;
		private const BMD_HEIGHT:int = 240;
		private var baseColor:uint = 0xFFFFFF;
		private var baseBmd:BitmapData;
		private var editBmd:BitmapData;
		private var noiseBmd:BitmapData;
		private var sandstormBmd:BitmapData;
		private var sorce:DisplayObject;
		private var baseMatrix:Matrix;
		private var pointArray:Array;
		private var randArray1:Array;
		private var randArray2:Array;
		private var randNum1:Number;
		private var bmdUpNum:Number;
        private var video:Video;
		private var _bmp:Bitmap;
        private var camera_width:int;
		private var camera_height:int;

		public function NoiseDisplay():void {
			camera_width = stage.stageWidth;
			camera_height = stage.stageHeight;
            video = new Video(camera_width, camera_height);
			var camera:Camera = Camera.getCamera();
			if (camera == null) {
				//error
				return;
			}
			video.attachCamera(camera);
			sorce = video;
			bmp = new Bitmap();
			addChild(bmp);
			baseBmd = new BitmapData(BMD_WIDTH, BMD_HEIGHT, false, baseColor);
			editBmd = baseBmd.clone();
			noiseBmd = baseBmd.clone();
			sandstormBmd = baseBmd.clone();
			baseMatrix = new Matrix();
			pointArray = new Array(new Point(0, 0), new Point(0, 0), new Point(0, 0));
			randArray1 = new Array(Math.random() + 1, Math.random() + 1, Math.random() + 1);
			randArray2 = new Array(0, 0, 0);
			randNum1 =0.5;
			bmdUpNum = 0;
			bmp.bitmapData = noiseBmd;
			bmp.smoothing = true;
			bmp.visible = false;
            stage.addEventListener(Event.RESIZE, _onResize);
			_onResize(null);
			addEventListener(Event.ENTER_FRAME, upDate);
			bmp.visible = true;
			sorce.visible = false;
		}
		private function _onResize(e:Event):void {
			var W:Number = stage.stageWidth;
			var H:Number = stage.stageHeight;
			baseMatrix = new Matrix();
			baseMatrix.scale(BMD_WIDTH/W, BMD_HEIGHT/H);
			bmp.scaleX = W/BMD_WIDTH;
			bmp.scaleY = H/BMD_HEIGHT;
			bmp.x = bmp.y = 0;
		}
		private var _keyCnt:Number = 0;
		private function upDate(e:Event):void {
			var copy_bmd:BitmapData = baseBmd.clone();
			copy_bmd.draw(sorce, baseMatrix);
			editBmd = copy_bmd.clone();
			
			for (var i:int = 0; i < 3; i++) {
				if (randArray1[i] >= 1){
					--randArray1[i];
					randArray2[i] = Math.random() / 4 + 0.03;
				} 
				randArray1[i] = randArray1[i] + randArray2[i];
				_keyCnt += (48-_keyCnt) / 4;
				pointArray[i].x = Math.ceil(Math.sin(randArray1[i] * Math.PI * 2) * randArray2[i] * _keyCnt*2);
				pointArray[i].y = 0;
			}
			
			var keyNum:Number = 1*(Math.abs(pointArray[0].x) + Math.abs(pointArray[1].x) + Math.abs(pointArray[2].x) + 8) / 4;

			i = BMD_HEIGHT;
			while (i--){
			    var offset:Number = Math.sin(i / BMD_HEIGHT * (Math.random() / 8 + 1) * randNum1 * Math.PI * 2)* 0.8 * keyNum * keyNum;
				editBmd.copyPixels(copy_bmd, new Rectangle(offset, i, BMD_WIDTH - offset, 1), new Point(0, i));
			}
			sandstormBmd.noise(int(Math.random() * 1000), 0, 255, 7, false);
			var sandNum:Number = 40;
			editBmd.merge(sandstormBmd, editBmd.rect, new Point(0,0), sandNum, sandNum, sandNum, 0);
			noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[0], BitmapDataChannel.RED, BitmapDataChannel.RED);
			noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[1], BitmapDataChannel.GREEN, BitmapDataChannel.GREEN);
			noiseBmd.copyChannel(editBmd, noiseBmd.rect, pointArray[2], BitmapDataChannel.BLUE, BitmapDataChannel.BLUE);
		}
	}
}