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

forked from: ドラえもん タイムマシーン

http://ton-up.net/blog/archives/254
ワープっぽく・・・見える?w


mouseMove : move perspective point
mouseDown : speed up
mouseUp   : speed down
/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/u5TO
 */

// forked from yasu's ドラえもん タイムマシーン
// forked from yasu's flash on 2010-5-17
// forked from ton's ワープっぽいなにか
// http://ton-up.net/blog/archives/254
/*
ワープっぽく・・・見える?w


mouseMove : move perspective point
mouseDown : speed up
mouseUp   : speed down
*/

package {
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.*;
    import flash.display.*;
    
    [SWF(width=465, height=465, backgroundColor=0x000000)]
    public class Warp extends Sprite {
        private const W:int = stage.stageWidth;
        private const H:int = stage.stageHeight;
        private const P : Number = 800;
        private const SY : Number = 2;
        private const R:Number = P * SY / (2 * Math.PI);
        private const PI:Number = Math.PI;
            
        private var _ox : Point;
        private var _stepX : Number;
            
        private var _bmds : Array;
        private var N : uint = 20;
        private var _bmd : BitmapData;
        
        private var perspective:PerspectiveProjection;
        private var _canvas : Sprite;

            public function Warp() {
                perspective = this.transform.perspectiveProjection;
                perspective.fieldOfView = 45;
                addEventListener(Event.ENTER_FRAME, onEnterFrameHandler);
                stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownHandler);
                stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpHandler);
                
                graphics.beginFill(0);
                graphics.drawRect(0, 0, W, H);
                graphics.endFill();
                
                _canvas = new Sprite();
                _canvas.x = stage.stageWidth / 2;
                _canvas.y = stage.stageHeight / 2;
                addChild(_canvas);
                
                _bmd = new BitmapData(200, P, false, 0x000000);
                _bmds = []; 
                for(var i : uint = 0;i < N;i++){
                		var bmd : BitmapData = new BitmapData(200, P / N, false, 0xffffff);
                		_bmds.push(bmd);
                		var bmp : Bitmap = new Bitmap(bmd);
                		bmp.x = R * Math.cos(i * 2 * Math.PI / N);
                		bmp.y = R * Math.sin(i * 2 * Math.PI / N);
                		bmp.z = 2000;
                		bmp.scaleX = 20;
                		bmp.scaleY = SY;
                		bmp.rotationX = -(i + 0.5) / N * 360;
                		bmp.rotationY = 90;
                		_canvas.addChild(bmp); 
                }
                
                _ox = new Point(int.MAX_VALUE, 0);
                _stepX = -5;
            }
            
        private function onMouseDownHandler(e:MouseEvent):void { _mode = false; }
        private function onMouseUpHandler(e:MouseEvent):void { _mode = true; }
        
        private var seed : int = new Date().time;
        private var _mode : Boolean = true;
            
        private function onEnterFrameHandler(e:Event):void {
            perspective.projectionCenter = new Point(mouseX, mouseY);
            _bmd.perlinNoise(100, 100, 1, seed, true, _mode, 5, false, [_ox]);
            _bmd.colorTransform(_bmd.rect, new ColorTransform(1.2, 1.2, 1.2));
            for(var i : uint = 0;i < N;i++){
            		_bmds[i].copyPixels(_bmd, new Rectangle(0, i / N * P, 200, P / N), new Point());
            }
            _ox.x += _stepX;
        }
    }
}