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

顔の位置で画面を動かす

...
---------------
design
http://studiocombo.pl/
---------------

webカメラ必須。
上下左右前後の顔の位置で画面が動きます。
暗い部屋を想定してるので明るい部屋だと微妙かも。
package 
{
	/**
* ...
* ---------------
* design
* http://studiocombo.pl/
* ---------------
* 
* webカメラ必須。
* 上下左右前後の顔の位置で画面が動きます。
* 暗い部屋を想定してるので明るい部屋だと微妙かも。
* 
*/
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.StatusEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.media.Camera;
	import flash.media.Video;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.system.Security;
	import flash.system.SecurityPanel;
	import org.papervision3d.materials.BitmapMaterial;
	import org.papervision3d.materials.ColorMaterial;
	import org.papervision3d.objects.primitives.Plane;
	import org.papervision3d.render.QuadrantRenderEngine;
	import org.papervision3d.view.BasicView;
	
	[SWF(backgroundColor="#111111", frameRate=30)]
	public class Main extends BasicView {
		private var video:Video;
		private var ca:Camera;
		private var bmd:BitmapData;
		private var bm:Bitmap;
		private var sp:Sprite;
		private var sp1:Sprite;
		
		private var f_width:int;
		private var f_height:int;
		
		private var Wset:int;
		private var Hset:int;
		private var Wpos:int;
		private var Hpos:int;
		private var Wnum:int;
		private var Hnum:int;
		
		private var count:int = 0;
		private var array:Array;
		
		private var Pt:Point;
		private var Rect:Rectangle;
		private var shikiichi:uint;
		private var color1:uint;
		private var color2:uint;
		private var maskColor:uint;
		public function Main() {
			Security.loadPolicyFile("http://mutast.heteml.jp/crossdomain.xml");
			renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
			Pt = new Point(0, 0);
			shikiichi = 0xff888888;
			color1 = 0xff000000;
			color2 = 0xffffffff;
			maskColor = 0xffffffff;
			
			array = new Array();
			
			imgload();
		}
		
		public function imgload():void {
			count ++;
			var loader:Loader = new Loader();
			var context:LoaderContext = new LoaderContext();
			context.checkPolicyFile = true;
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
			loader.load(new URLRequest("http://mutast.heteml.jp/works/sozai4/s" + count + ".png"), context);
		}
		
		public function loaded(e:Event):void {
			var b:BitmapData = Bitmap(e.target.loader.content).bitmapData;
			var mat:BitmapMaterial = new BitmapMaterial(b,true);
			//mat.smooth = true;
			var p:Plane = new Plane(mat, 662, 552);
			
			scene.addChild(p);
			array.push(p);
			
			if (count < 6) {
				imgload();
			}else {
				loadend();
			}
		}
		public function loadend():void {
			
			startRendering();
			Cameracap();
			camera.z = camera.focus * camera.zoom * -1;
			
			array[0].z = 500;
			array[0].scaleX = array[0].scaleY = 2;
			array[1].z = 250;
			array[1].y -= 20;
			array[1].scaleX = array[1].scaleY = 1.3;
			array[2].z = 80;
			array[2].rotationX = 70;
			array[2].y -= 250;
			array[2].x -= 100;
			array[2].scaleX = 1.2;
			array[2].scaleY = 0.6;
			array[4].z -= 20;
			array[5].z -= 100;
		}
		
		
		
		public function Cameracap():void {
			video = new Video(100, 80);
			ca = new Camera();
			ca = Camera.getCamera();
			sp = new Sprite();
			sp1 = new Sprite();
			bmd = new BitmapData(video.width, video.height / 2);
			Rect = new Rectangle(0, 0, bmd.width, bmd.height);
			bm = new Bitmap(bmd);
			bm.x = bm.y = 0;
			
			if (ca != null) {
				if (ca.muted) {
					Security.showSettings(SecurityPanel.PRIVACY);
					ca.addEventListener(StatusEvent.STATUS, statusHandler);
				}else {
					//trace("hit");
				}
			}
		}
		
		public function statusHandler(e:StatusEvent):void {
			video.attachCamera(ca);
			addEventListener(Event.ENTER_FRAME, loop);
			//addChild(bm);
		}
		
		public function loop(e:Event):void {
			var num:int = 0;
			bmd.fillRect(Rect, 0xffffff);
			bmd.draw(video);
			
			bmd.threshold(bmd, Rect, Pt, "<", shikiichi, color1, maskColor, true);
			bmd.threshold(bmd, Rect, Pt, ">", shikiichi, color2, maskColor, true);
			
			//横幅
			Wset = 0;
			Wnum = 0;
			for (var i:int = 0; i < 100; i++) {
				var count1:int = 0;
				for (var j:int = 0; j < 40; j++) {
					var getcol:uint = bmd.getPixel(i, j);
					if (getcol != 0) {
						count1 ++;
						Wnum += (i - 50);
					}
				}
				if (count1 > 10) {
					Wset ++;
				}
			}
			Wpos = -1000 * (Wnum / 50000);
			camera.x += (Wpos - camera.x) / 10;
			
			//縦幅
			Hset = 0;
			Hnum = 0;
			for (i = 0; i < 40; i++) {
				count1 = 0;
				for (j = 0; j < 100; j++) {
					getcol = bmd.getPixel(j, i);
					if (getcol != 0) {
						count1 ++;
						Hnum ++;
					}
				}
				if (count1 > 10) {
					num ++;
				}
				if (count1 > 3) {
					if (Hset != 0) {
						Hset = Math.min(Hset, i);
					}else {
						Hset = i;
					}
				}
			}
			Hpos = -(20 * Hset) + 400;
			camera.y += (Hpos - camera.y) / 10;
			
			var max:int = Math.max(Wset, num);
			max = -1000 + max * 20;
			camera.z += (max - camera.z)/10;
			
		}
	}
}