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

wriggle

Use "-" and "+" move focalLength
Get Adobe Flash player
by iooi 24 Jun 2014

    Talk

    iooi at 28 Sep 2010 09:17
    Use "-" and "+" move focalLength
    Embed
/**
 * Copyright iooi ( http://wonderfl.net/user/iooi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lYgF
 */

package
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.display.Stage;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Matrix3D;
    import flash.geom.PerspectiveProjection;
    import flash.geom.Point;
    import flash.geom.Vector3D;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    
    /**
     * ...
     * @author case
     */
    public class MySprite extends Sprite
    {
        private var ImgSp:Sprite
        private var Bit:Bitmap
        private var Num:int = 20
        private var PA:Array = new Array()
        private var ImgW:int = 1000
        private var M3D:Matrix3D
        private var Per:PerspectiveProjection
        private var phase:Phase = new Phase()
        private var Ang:Number = 30
        private var BitA:Array = new Array()
        
        
        public function MySprite() 
        {
            this.transform.matrix3D = new Matrix3D()
            M3D = this.transform.matrix3D
            this.transform.perspectiveProjection = new PerspectiveProjection()
            Per = this.transform.perspectiveProjection
            this.y = stage.stageWidth / 2
            
            Per.projectionCenter = new Point(stage.stageWidth, -100)
            this.Per.focalLength = 370
            var l:Loader = new Loader()
            l.contentLoaderInfo.addEventListener(Event.COMPLETE, ImgCom)
            l.load(new URLRequest("https://d13yacurqjgara.cloudfront.net/users/4404/screenshots/273545/car.jpg"),new LoaderContext(true));    
        }
        
        private function ImgCom(e:Event):void
        {
            Bit = e.target.content as Bitmap
            ImgSp = new Sprite()
            ImgSp.graphics.beginBitmapFill(Bit.bitmapData,null,true)
            ImgSp.graphics.drawRect(0, 0, ImgW, 300)
            ImgSp.graphics.endFill()
            
            var _bitw:int = ImgW / Num;
            phase.value = 0
            for (var i:int = 0; i < Num; i++) 
            {
                var _bit:BitmapData = new BitmapData(_bitw, 300, false, 0x000000)
                BitA.push(_bit)
                _bit.draw(ImgSp, new Matrix(1, 0, 0, 1, -i * _bitw, 0))
                var bit:Bitmap = new Bitmap(_bit)
                bit.smoothing = true
                var sp:My3DSprite = new My3DSprite(_bitw)
                PA.push(sp)
                
                addChildAt(sp,0)
                sp.addChild(bit)
                if (i > -1)
                {
                    
                    phase.value += .2
                    var v3:Vector.<Vector3D> = new Vector.<Vector3D>(3);
                    v3 = sp.M3D.decompose()
                    v3[1].incrementBy(new Vector3D(0, (Ang * phase.phasedValue - 45)*Math.PI/180, 0))
                    sp.M3D.recompose(v3)
                    //sp.M3D.appendRotation(,Vector3D.Y_AXIS)
                    
                }
                
                if (i == 0 ) continue
                
                var _m3d:Matrix3D = PA[i-1].sp.M3D.clone()
                _m3d.append(PA[i-1].M3D)
                sp.x = _m3d.decompose()[0].x
                sp.z = _m3d.decompose()[0].z
                
            }
            addEventListener(Event.ENTER_FRAME,onEnterFrame)
            stage.addEventListener(MouseEvent.MOUSE_WHEEL, Wheel)
            stage.addEventListener(KeyboardEvent.KEY_DOWN,UseKey)
        }
        private var Tx:int = 0
        private var _phase:Number = 1
        private function onEnterFrame(e:Event):void
        {
            var _bitw:int = ImgW / Num;
            Tx += 5
            ImgSp.graphics.clear()
            ImgSp.graphics.beginBitmapFill(Bit.bitmapData,new Matrix(1,0,0,1,Tx,0),true)
            ImgSp.graphics.drawRect(0, 0, ImgW, 300)
            ImgSp.graphics.endFill()
            _phase += .1
            phase.value = _phase
            for (var i:int = 0; i < Num; i++) 
            {
                
                BitA[i].draw(ImgSp, new Matrix(1, 0, 0, 1, -i * _bitw, 0))
                phase.value += .2
                    var v3:Vector.<Vector3D> = new Vector.<Vector3D>(3);
                    v3 = PA[i].M3D.decompose()
                    v3[1].y = (Ang * phase.phasedValue - 60)*Math.PI/180
                    PA[i].M3D.recompose(v3)
                if (i == 0 ) continue
                var _m3d:Matrix3D = PA[i-1].sp.M3D.clone()
                _m3d.append(PA[i-1].M3D)
                PA[i].x = _m3d.decompose()[0].x
                PA[i].z = _m3d.decompose()[0].z
            }
        }
        
        private function Wheel(e:MouseEvent):void
        {
            var PerF:Number = this.Per.focalLength + e.delta * 10
            if (PerF < 80) PerF = 80
            this.Per.focalLength = PerF
        }
        
        private function UseKey(e:KeyboardEvent):void
        {
            trace(e.keyCode)
            var PerF:Number
            switch(e.keyCode)
            {
                case 189:
                PerF = this.Per.focalLength + 10
                break;
                case 187:
                PerF = this.Per.focalLength - 10
                break;
            }
            trace(PerF)
            if (PerF < 80) PerF = 80
            this.Per.focalLength = PerF
        }
        
    }
    
}


    class Phase {
        
        private var v:Number;
        
        public function Phase(v:Number=0) {
            this.v = v;
        }
        
        public function get value():Number {
            return v;
        }
        
        public function set value(v:Number):void {
            this.v = v;
        }
        
        public function get phasedValue():Number {
            return Math.sin(v);
        }

        public function get absPhasedValue():Number {
            return Math.abs(phasedValue);
        }

        public function get normValue():Number {
            return (phasedValue+1)/2;
        }

    }
    
    
    
    import flash.display.Sprite;
    import flash.geom.Matrix3D;
    import flash.geom.PerspectiveProjection;
    
    /**
     * ...
     * @author case
     */
    class My3D extends Sprite
    {
        public var M3D:Matrix3D
        public function My3D() 
        {
            this.transform.matrix3D = new Matrix3D()
            M3D = this.transform.matrix3D
        }
        
    }
    
    import flash.display.Sprite;
    
    /**
     * ...
     * @author case
     */
    class My3DSprite extends My3D
    {
        public var sp:My3D = new My3D()
        public function My3DSprite(spx:Number) 
        {
            addChild(sp)
            sp.x = spx
        }
        
    }