Beautifl - Flash Gallery

Thumbnail : Pixel Bender Test
Pixel Bender Test
northprint 2009-08-27 All rights reserved

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

// write as3 code here..
//Pixel Bender Test
package {
    import flash.display.*;
    import flash.events.*;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLLoaderDataFormat;
    import flash.system.Security;
    import flash.filters.ShaderFilter;
    import flash.system.LoaderContext;

    [SWF(backgroundColor="#ffffff")]

    public class PixelBenderTest extends MovieClip{  

        private var _pbloader:URLLoader;
        private var _imgloader:Loader;
        private var _twirlShader:Shader;
        private var _filter:ShaderFilter;
        private var _bmp:Bitmap;

        public function PixelBenderTest(){
            Security.loadPolicyFile("http://narayama.heteml.jp/crossdomain.xml");
            _pbloader = new URLLoader();
            _pbloader.dataFormat = URLLoaderDataFormat.BINARY;
            _pbloader.addEventListener(Event.COMPLETE,PbLoadHandler);
            _pbloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/twirlFlash.pbj"));
        }
        private function PbLoadHandler(e:Event):void{
            _imgloader = new Loader();
            _imgloader.contentLoaderInfo.addEventListener(Event.COMPLETE,ImgLoadHandler);
            _imgloader.load(new URLRequest("http://narayama.heteml.jp/test/pixelbender/testimage.jpg"), new LoaderContext(true));
        }
        private function ImgLoadHandler(e:Event):void{
            var loaderInfo:LoaderInfo = LoaderInfo(e.currentTarget);
            var loader:Loader = loaderInfo.loader;
            var bmd:BitmapData = new BitmapData(loader.width, loader.height, true);
            bmd.draw(loader);

            _bmp = new Bitmap(bmd);
            _bmp.x = (stage.stageWidth/2) - (loader.width/2);
            _bmp.y = (stage.stageHeight/2) - (loader.height/2);

            _twirlShader = new Shader(_pbloader.data);
            _twirlShader.data["radius"]["value"] = [100];
            _twirlShader.data["twist"]["value"] = [5];

            _filter = new ShaderFilter(_twirlShader);

            _bmp.filters = [_filter];
            addChild(_bmp);

            addEventListener(Event.ENTER_FRAME,EnterframeHandler);
        }
        private function EnterframeHandler(e:Event):void{
            _twirlShader.data["center"]["value"] = [_bmp.mouseX,_bmp.mouseY];
            _bmp.filters = [_filter];
        }
    }
}