perspectiveProjection (2)

by ProjectNya forked from perspectiveProjection (diff: 8)
//////////////////////////////////////////////////////////////////////////////
perspectiveProjection
//////////////////////////////////////////////////////////////////////////////
♥0 | Line 53 | Modified 2010-07-20 00:46:25 | MIT License | (replaced)
play

ActionScript3 source code

/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/iqEN
 */

// forked from ProjectNya's perspectiveProjection
////////////////////////////////////////////////////////////////////////////////
// perspectiveProjection
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.BitmapData;
    import flash.display.Bitmap;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;

    [SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var loader:Loader;
        private var bitmapData:BitmapData;
        private static var basePath:String = "http://assets.wonderfl.net/images/related_images/";
        private static var imagePath:String = "c/c5/c5c1/c5c18f40978ea4273202e5b2ed211caf404ec9bf";
        private var canvas:Sprite;
        private var vertices:Vector.<Number>;
        private var indices:Vector.<int>;
        private var uvData:Vector.<Number>;

        public function Main() {
            //Wonderfl.capture_delay(1);
            init();
        }

        private function init():void {
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.INIT, initialize, false, 0, true);
            loader.load(new URLRequest(basePath + imagePath), new LoaderContext(true));
            root.transform.perspectiveProjection.fieldOfView = 120;
            //root.transform.perspectiveProjection.focalLength = 300
            vertices = new Vector.<Number>;
            vertices.push(0, 0);
            vertices.push(150, 0);
            vertices.push(150, 150);
            vertices.push(0, 150);
            indices = new Vector.<int>;
            indices.push(0, 1, 2);
            indices.push(0, 2, 3);
            uvData = new Vector.<Number>;
            uvData.push(0, 0);
            uvData.push(1, 0);
            uvData.push(1, 1);
            uvData.push(0, 1);
        }
        private function initialize(evt:Event):void {
            bitmapData = Bitmap(evt.target.content).bitmapData;
            canvas  = new Sprite();
            canvas.graphics.beginBitmapFill(bitmapData);
            canvas.graphics.drawTriangles(vertices, indices, uvData);
            canvas.graphics.endFill();
            canvas.x = stage.stageWidth / 2 - canvas.width /2;
            canvas.y = stage.stageHeight / 2 - canvas.height / 2;
            addChild(canvas);
            canvas.rotationX = -30;
        }

    }

}