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

RasterEffect

RasterEffect
* 
* いわゆるラスタースクロール
* 一昔前のシューティングゲームの背景っぽい
* 
* ダライアス外伝 Hゾーンのボス戦のイメージ
* http://www.youtube.com/watch?v=R3HJLJBoXOE
* 
* ◆マウスカーソルにおうじてうねうねが移動 
* ◆ステージをマウスダウンで横揺れでの基準点が可視化
* 
* ◆可変パラメータ 
* ChangeImage:元画像の変更>perlinNoise/jpg画像/webカメラ
* friction:横ゆれの抵抗
* spring:横ゆれのバネ定数
* frequency:縦ゆれの振幅
* elasticity:縦ゆれの揺れ具合
* eSpeed:縦ゆれの速度
* Horizon/Vertical:揺れの方向
* repeat:横揺れ方向に画像を繋ぐ
* BlendMode:perlinNoiseのときのみ
* 
* ※webカメラについてはrepeatが強制off。
* (手抜き)
* 
* ※縦ゆれ処理は↓を参考
* http://wonderfl.net/c/jARn
* 
*
/**
 * Copyright sakusan393 ( http://wonderfl.net/user/sakusan393 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/lTDX
 */

/*
 * 
 * RasterEffect
 * 
 * いわゆるラスタースクロール
 * 一昔前のシューティングゲームの背景っぽい
 * 
 * ダライアス外伝 Hゾーンのボス戦のイメージ
 * http://www.youtube.com/watch?v=R3HJLJBoXOE
 * 
 * ◆マウスカーソルにおうじてうねうねが移動 
 * ◆ステージをマウスダウンで横揺れでの基準点が可視化
 * 
 * ◆可変パラメータ 
 * ChangeImage:元画像の変更>perlinNoise/jpg画像/webカメラ
 * friction:横ゆれの抵抗
 * spring:横ゆれのバネ定数
 * frequency:縦ゆれの振幅
 * elasticity:縦ゆれの揺れ具合
 * eSpeed:縦ゆれの速度
 * Horizon/Vertical:揺れの方向
 * repeat:横揺れ方向に画像を繋ぐ
 * BlendMode:perlinNoiseのときのみ
 * 
 * ※webカメラについてはrepeatが強制off。
 * (手抜き)
 * 
 * ※縦ゆれ処理は↓を参考
 * http://wonderfl.net/c/jARn
 * 
 * */
 
package  
{
    import com.bit101.components.CheckBox;
    import com.bit101.components.ComboBox;
    import com.bit101.components.HSlider;
    import com.bit101.components.Label;
    import com.bit101.components.RadioButton;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.Loader;
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;
    import flash.media.Camera;
    import flash.media.Video;
    import flash.net.URLRequest;
    import flash.system.LoaderContext;
    import flash.system.Security;
    import net.hires.debug.Stats;
    
    [SWF(width="465", height="465", backgroundColor="0x0", frameRate="60")] 

    
    /**
     * ...
     * @author 393
     */
    public class RasterTestV extends Sprite
    {
        private var _h:int;
        private var _w:int;
        private var _chaser:Point;
        private var _container:Sprite;
        private var _raster1:RasterImage;
        private var _raster2:RasterImage;
        private var _video:Video;
        private var _videoBmd:BitmapData;
        private var _imageBmd:BitmapData;
        
        private var _friction1:Number = 0.99;
        private var _friction2:Number = 0.99;
        private var _spring1:Number = 0.03;
        private var _spring2:Number = 0.04;
        
        private var _frequency1:int = 140;
        private var _frequency2:int = 100;
        private var _elasticity1:int = 40;
        private var _elasticity2:int = 35;
        private var _elasticSpeed1:int = 300;
        private var _elasticSpeed2:int = 200;
        
        private var _isHorizon1:Boolean = true;
        private var _isHorizon2:Boolean = true;
        private var _isRepeat1:Boolean = true;
        private var _isRepeat2:Boolean = true;
        
        private var _currentIndex:int;
        private var _friction1Label:Label;
        private var _friction2Label:Label;
        private var _spring1Label:Label;
        private var _spring2Label:Label;
        private var _compoContainer:Sprite;
        private var _blendModeStr:String = BlendMode.NORMAL;
        private var _check1:CheckBox;
        private var _isMouseDown:Boolean;
        private var _angleCount:Number = 0;
        private var _frequency1Label:Label;
        private var _frequency2Label:Label;
        private var _elasticity1Label:Label;
        private var _elasticity2Label:Label;
        private var _elasticitySpeed1Label:Label;
        private var _elasticitySpeed2Label:Label;
        
        public function RasterTestV() 
        {
            Security.loadPolicyFile("http://assets.wonderfl.net/crossdomain.xml");
            var loader:Loader = new Loader();
            loader.load(new URLRequest("http://assets.wonderfl.net/images/related_images/c/ce/ce16/ce162c9e23acb069c631df66fb01ba8c4ab2174b"));
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoadCompleteHandler);
        }
        
        private function imgLoadCompleteHandler(e:Event):void 
        {
            _imageBmd = BitmapData(e.target.content.bitmapData);
            init();
        }
        
        private function init():void 
        {
            stage.align = StageAlign.TOP_LEFT;
            
            _w = stage.stageWidth;
            _h = stage.stageHeight;
            
            _chaser = new Point();
            
            addChild(_container = new Sprite());
            //removeChild(_container);
            
            setComponent();
            
            changeImage(0);
            
            stage.addEventListener(MouseEvent.MOUSE_DOWN, downHandler);
            stage.addEventListener(MouseEvent.MOUSE_UP, upHandler);
        }
        
        private function upHandler(e:MouseEvent):void 
        {
            _isMouseDown = false;
        }
        
        private function downHandler(e:MouseEvent):void 
        {
            _isMouseDown = true;
        }
        
        private function setComponent():void
        {
            //BimapDataソースの洗濯
            var box:ComboBox = new ComboBox(this, 3, 3,"ChangeImage");
            box.addItem("PerlinNoise");
            box.addItem("Image");
            box.addItem("WebCam");
            box.addEventListener(Event.SELECT, onSelect);
            
            _compoContainer = new Sprite();
            addChild(_compoContainer);
            
            //抵抗値1
            var friction1Slider:HSlider = new HSlider(this, 110, 3, frictionChange);
            friction1Slider.maximum = 1;
            friction1Slider.minimum = 0.01;
            friction1Slider.tick = 0.01
            friction1Slider.value = _friction1
            friction1Slider.name = "1";
            _friction1Label = new Label(this, 210, 0, "friction1:"+_friction1);
            //抵抗値2
            var friction2Slider:HSlider = new HSlider(_compoContainer, 310-30, 3, frictionChange);
            friction2Slider.maximum = 1;
            friction2Slider.minimum = 0.01;
            friction2Slider.tick = 0.01
            friction2Slider.value = _friction2
            friction2Slider.name = "2";
            _friction2Label = new Label(_compoContainer, 410-30, 0, "friction2:"+_friction2);
            //バネ係数1
            var spring1Slider:HSlider = new HSlider(this, 110, 15, springChange);
            spring1Slider.maximum = 0.5;
            spring1Slider.minimum = 0.01;
            spring1Slider.tick = 0.01
            spring1Slider.value = _spring1;
            spring1Slider.name = "1";
            _spring1Label = new Label(this, 210, 10, "spring1:" + _spring1);
            //バネ係数2
            var spring2Slider:HSlider = new HSlider(_compoContainer, 310-30, 15, springChange);
            spring2Slider.maximum = 0.5;
            spring2Slider.minimum = 0.01;
            spring2Slider.tick = 0.01
            spring2Slider.value = _spring2;
            spring2Slider.name = "2";
            _spring2Label = new Label(_compoContainer, 410 - 30, 10, "spring2:" + _spring2);
            
            //伸縮幅1
            var frequency1Slider:HSlider = new HSlider(this, 110, 35, frequencyChange);
            frequency1Slider.maximum = 200;
            frequency1Slider.minimum = 0;
            frequency1Slider.tick = 1;
            frequency1Slider.value = _frequency1
            frequency1Slider.name = "1";
            _frequency1Label = new Label(this, 210, 30, "frequency1:"+_frequency1);
            //伸縮幅2
            var frequency2Slider:HSlider = new HSlider(_compoContainer, 310-30, 35, frequencyChange);
            frequency2Slider.maximum = 200;
            frequency2Slider.minimum = 0;
            frequency2Slider.tick = 1;
            frequency2Slider.value = _frequency2;
            frequency2Slider.name = "2";
            _frequency2Label = new Label(_compoContainer, 410 - 30, 30, "frequency2:" + _frequency2);
            //伸縮率1
            var elasticity1Slider:HSlider = new HSlider(this, 110, 47, elasticityChange);
            elasticity1Slider.maximum = 200;
            elasticity1Slider.minimum = 0;
            elasticity1Slider.tick = 1;
            elasticity1Slider.value = _elasticity1
            elasticity1Slider.name = "1";
            _elasticity1Label = new Label(this, 210, 42, "elasticity1:"+_elasticity1);
            //伸縮率2
            var elasticity2Slider:HSlider = new HSlider(_compoContainer, 310-30, 47, elasticityChange);
            elasticity2Slider.maximum = 200;
            elasticity2Slider.minimum = 0;
            elasticity2Slider.tick = 1;
            elasticity2Slider.value = _elasticity2;
            elasticity2Slider.name = "2";
            _elasticity2Label = new Label(_compoContainer, 410 - 30, 42, "elasticity2:" + _elasticity2);
            //伸縮速度1
            var elasticitySpeed1Slider:HSlider = new HSlider(this, 110, 59, elasticitySpeedChange);
            elasticitySpeed1Slider.maximum = 3000;
            elasticitySpeed1Slider.minimum = 0;
            elasticitySpeed1Slider.tick = 10;
            elasticitySpeed1Slider.value = _elasticSpeed1;
            elasticitySpeed1Slider.name = "1";
            _elasticitySpeed1Label = new Label(this, 210, 52, "eSpeed1:"+_elasticSpeed1);
            //伸縮速度2
            var elasticitySpeed2Slider:HSlider = new HSlider(_compoContainer, 310 - 30, 59, elasticitySpeedChange);
            elasticitySpeed2Slider.maximum = 3000;
            elasticitySpeed2Slider.minimum = 0;
            elasticitySpeed2Slider.tick = 10;
            elasticitySpeed2Slider.value = _elasticSpeed2;
            elasticitySpeed2Slider.name = "2";
            _elasticitySpeed2Label = new Label(_compoContainer, 410 - 30, 52, "eSpeed2:" + _elasticSpeed2);
                        
            //揺れ方向1
            var button1:RadioButton = new RadioButton(this, 110, 30+50, "Horizon", true, radioSelect);
            var button2:RadioButton = new RadioButton(this, 110, 40+50, "Vertical", false, radioSelect);
            button1.groupName = "raster1";
            button2.groupName = "raster1";
            //揺れ方向2
            var button3:RadioButton = new RadioButton(_compoContainer, 310-30, 30+50, "Horizon", true, radioSelect2);
            var button4:RadioButton = new RadioButton(_compoContainer, 310-30, 40+50, "Vertical", false, radioSelect2);
            button3.groupName = "raster2";
            button4.groupName = "raster2";
            
            //画像繰り返し1
            _check1 = new CheckBox(this, 170, 30+50, "repeat", checkClick);
            _check1.selected = true;
            _check1.name = "1";
            //画像繰り返し2
            var check2:CheckBox = new CheckBox(_compoContainer, 370 - 30, 30+50, "repeat", checkClick);
            check2.selected = true;
            check2.name = "2";
            
            //ブレンドモード
            var box2:ComboBox = new ComboBox(_compoContainer, 310-30, 60+50,"BlendMode");
            box2.addItem(BlendMode.NORMAL);
            box2.addItem(BlendMode.ADD);
            box2.addItem(BlendMode.ALPHA);
            box2.addItem(BlendMode.DARKEN);
            box2.addItem(BlendMode.DIFFERENCE);
            box2.addItem(BlendMode.ERASE);
            box2.addItem(BlendMode.HARDLIGHT);
            box2.addItem(BlendMode.INVERT);
            box2.addItem(BlendMode.LAYER);
            box2.addItem(BlendMode.LIGHTEN);
            box2.addItem(BlendMode.MULTIPLY);
            box2.addItem(BlendMode.OVERLAY);
            box2.addItem(BlendMode.SCREEN);
            box2.addItem(BlendMode.SHADER);
            box2.addItem(BlendMode.SUBTRACT);
            box2.addEventListener(Event.SELECT, changeBlendMode);
            
            var stats:Stats = new Stats();
            stats.x = 3;
            addChild(stats).y = 40;
        }
        
        private function elasticitySpeedChange(e:Event):void
        {
            trace("e.currentTarget.name : " + e.currentTarget.name);
            if (e.currentTarget.name == "1")    _elasticSpeed1 =  e.currentTarget.value;
            else  _elasticSpeed2 =  e.currentTarget.value;
            trace("_elasticSpeed1 : " + _elasticSpeed1);
            
            if (_raster1)  _raster1.elasticSpeed = _elasticSpeed1;
            if (_raster2)  _raster2.elasticSpeed = _elasticSpeed2;
            _elasticitySpeed1Label.text = "eSpeed1:"+_elasticSpeed1;
            _elasticitySpeed2Label.text = "eSpeed2:"+_elasticSpeed2;
        }
        
        private function elasticityChange(e:Event):void
        {
            if (e.currentTarget.name == "1")    _elasticity1 =  e.currentTarget.value;
            else  _elasticity2=  e.currentTarget.value;
            
            if (_raster1)  _raster1.elasticity = _elasticity1;
            if (_raster2)  _raster2.elasticity = _elasticity2;
            _elasticity1Label.text = "elasticity1:"+_elasticity1;
            _elasticity2Label.text = "elasticity2:"+_elasticity2;
        }
        
        private function frequencyChange(e:Event):void
        {
            if (e.currentTarget.name == "1")    _frequency1 =  e.currentTarget.value;
            else _frequency2 =  e.currentTarget.value;
            
            if (_raster1)  _raster1.frequency = _frequency1;
            if (_raster2)  _raster2.frequency = _frequency2;
            _frequency1Label.text = "frequency1:"+_frequency1;
            _frequency2Label.text = "frequency2:"+_frequency2;
        }
        
        private function changeBlendMode(e:Event):void 
        {
            var box:ComboBox = e.currentTarget as ComboBox;
            _blendModeStr = box.selectedItem.toString();
            changeImage(_currentIndex);
        }
        
        private function checkClick(e:Event):void
        {
            if (e.currentTarget.name == "1") _isRepeat1 = e.currentTarget.selected;
            else _isRepeat2 = e.currentTarget.selected;
            changeImage(_currentIndex);
        }
        private function frictionChange(e:Event):void
        {
            trace("e.currentTarget.name : " + e.currentTarget.name);
            if (e.currentTarget.name == "1")    _friction1 =  e.currentTarget.value;
            else _friction2 =  e.currentTarget.value;
            
            if (_raster1) if (_raster1.friction) _raster1.friction = _friction1;
            if (_raster2) if (_raster2.friction) _raster2.friction = _friction2;
            _friction1Label.text = "friction1:"+_friction1;
            _friction2Label.text = "friction2:"+_friction2;
        }         
        private function springChange(e:Event):void
        {
            if (e.currentTarget.name == "1")    _spring1 = e.currentTarget.value;
            else _spring2 = e.currentTarget.value;
            if (_raster1) if (_raster1.spring) _raster1.spring = _spring1;
            if (_raster2) if (_raster2.spring) _raster2.spring = _spring2;
            _spring1Label.text = "spring1:"+_spring1;
            _spring2Label.text = "spring2:"+_spring2;
        }
 
        private function radioSelect(e:Event):void
        {
            if (e.currentTarget.label == "Horizon") _isHorizon1 = true;
            else _isHorizon1 = false;
            changeImage(_currentIndex);
        }
        private function radioSelect2(e:Event):void
        {
            if (e.currentTarget.label == "Horizon") _isHorizon2 = true;
            else _isHorizon2 = false;
            changeImage(_currentIndex);
        }
        private function changeImage(currentIndex:int):void
        {
            removeRaster();
            
            var bmd1:BitmapData , bmd2:BitmapData;
            
            if (currentIndex == 0) _compoContainer.visible = true;
            else _compoContainer.visible = false;
            //Imageソースの選択
            switch(currentIndex)
            {
                //Perlinnoise
                case 0:
                    bmd1 = new BitmapData(_w, _h);
                    bmd1.perlinNoise(128, 64, 1, Math.random() * 0xFFFF,true, true, (1 | 8));
                    bmd2 = new BitmapData(_w, _h);
                    bmd2.perlinNoise(129, 64, 1, Math.random() * 0xFFFF, true, true, (2 | 8));
                break;
                //jpg画像
                case 1:
                    bmd1 = _imageBmd.clone();
                break;
                //WEBカメラ
                case 2:
                    var webCamera:Camera = Camera.getCamera();
                    _video = new Video(_w, _h);
                    _video.attachCamera(webCamera);
                    _videoBmd = new BitmapData(_w, _h);
                    bmd1 = _videoBmd;
                    this.addEventListener(Event.ENTER_FRAME, videoEnterFrameHandler);
                    _isRepeat1 = false;
                    _check1.selected = false;
                    
                break;
            }
            trace("bmd1 : " + bmd1);
            _raster1 = new RasterImage(bmd1, _chaser, _spring1, _friction1,_frequency1,_elasticity1,_elasticSpeed1, _isHorizon1, _isRepeat1);
            trace("_raster1 : " + _raster1);
            addChildAt(_raster1, 0);
            if (currentIndex == 0) 
            {
                _raster2 = new RasterImage(bmd2, _chaser, _spring2, _friction2,_frequency2,_elasticity2,_elasticSpeed2, _isHorizon2, _isRepeat2);
                addChildAt(_raster2, 1);
                _raster2.blendMode = _blendModeStr;
            }
            this.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            trace("end");
        }
        
        private function onSelect(event:Event):void
        {
            var box:ComboBox = event.currentTarget as ComboBox;
            _currentIndex = box.selectedIndex;
            changeImage(_currentIndex);
        }
        private function videoEnterFrameHandler(e:Event):void 
        {
            _videoBmd.draw(_video);
        }
        
        private function removeRaster():void 
        {
            _container.graphics.clear();
            this.removeEventListener(Event.ENTER_FRAME, enterFrameHandler);
            if(_raster1) if(_raster1.parent) this.removeChild(_raster1);
            if(_raster2) if (_raster2.parent) this.removeChild(_raster2);
            _raster1 = null;
            _raster2 = null;
            
            this.removeEventListener(Event.ENTER_FRAME, videoEnterFrameHandler);
            _video = null;
            if(_videoBmd) _videoBmd.dispose();
        }
        
        private function enterFrameHandler(e:Event):void 
        {
            var x:Number = mouseX;
            var y:Number = mouseY;
            _angleCount += Math.random() * .1+.2;
            
            _chaser.x = x + 40*Math.sin(_angleCount*0.5)
            _chaser.y = y + 40 * Math.cos(_angleCount*0.3);
            
            _container.graphics.clear();
            if (!_isMouseDown) return;
            for (var i:int = 0; i < _raster1.pointVector.length; i++)
            {
                _container.graphics.beginFill(0xFF6666);
                _container.graphics.drawCircle(_raster1.pointVector[i].posX, _raster1.pointVector[i].posY, 2);
                _container.graphics.endFill();
                if (_currentIndex==0)
                {
                    _container.graphics.beginFill(0x6666FF);
                    _container.graphics.drawCircle(_raster2.pointVector[i].posX, _raster2.pointVector[i].posY, 2);
                    _container.graphics.endFill();
                }
            }
            _container.graphics.beginFill(0xFFFFFF);
            _container.graphics.drawCircle(_chaser.x, _chaser.y, 10);
        }
        
        
        
    }

}
import flash.display.*;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.geom.Rectangle;

class RasterImage extends Sprite
{
    private var _pointVector:Vector.<PhysicalPoint>;
    private var _isHorizon:Boolean;
    private var _target:Point;
    
    private var _sourceBmd:BitmapData;
    private var _canvasBmd:BitmapData;
    
    private var _sourceH:int;
    private var _sourceW:int;
    private var _length:int;
    
    private var _friction:Number;
    private var _spring:Number;
    
    private var _copyRect:int;
    private var _startPoint:int;
    private var _pointOffset:int;
    
    private var _frequency:int = 10;
    private var _elasticity:int = 100;
    private var _elasticSpeed:int = 1000;
    private var _elasticSpeedPosition:int = 0;
    
    
    public function RasterImage(sourceBmd:BitmapData,target:Point,spring:Number = 0.1,friction:Number = 0.99,frequency:int = 100,elasticity:int =40,elasticitySpeed:int = 1000,isHorizon:Boolean = true,isRepeat:Boolean = false )
    {
        this.addEventListener(Event.ADDED_TO_STAGE , init);
        
        _target = target;
        _friction = friction;
        _spring = spring;
        _frequency = frequency;
        _elasticity = elasticity;
        _elasticSpeed = elasticitySpeed;

        //ビットマップデータの大きさを保持
        _sourceW = sourceBmd.width;
        _sourceH = sourceBmd.height;
        var i:int;
        
        //画像リピート
        //画像をリピートする
        if (isRepeat)
        {
            //振れ方向が横の場合
            if (isHorizon)
            {
                _copyRect = _sourceW * 3;
                _startPoint = _sourceW * 1.5;
                _sourceBmd = new BitmapData(sourceBmd.width * 3, sourceBmd.height * 3);
                for(i = 0; i< 3; i++)
                {
                    _sourceBmd.copyPixels(sourceBmd,new Rectangle(0,0,sourceBmd.width,sourceBmd.height),new Point(sourceBmd.width*i,0));
                }    
            }
            //振れ方向が縦の場合
            else
            {
                _copyRect = _sourceH * 3;
                _startPoint = _sourceH * 1.5;
                _sourceBmd = new BitmapData(sourceBmd.width * 3, sourceBmd.height * 3);
                for(i = 0; i< 3; i++)
                {
                    _sourceBmd.copyPixels(sourceBmd,new Rectangle(0,0,sourceBmd.width,sourceBmd.height),new Point(0,sourceBmd.height*i));
                }    
            }
        }
        //画像をリピートしない
        else
        {
            _copyRect = _sourceW;
            _startPoint = _sourceW / 2;
            _sourceBmd = sourceBmd;
            
        }
        //振れ方向
        //横方向
        if (isHorizon) 
        {
            _pointOffset = _sourceW / 2;
            this.addEventListener(Event.ENTER_FRAME, horizonEnterFrameHandler);
            _length = _sourceH;
            //幅分のポイントデータ格納用
            _pointVector = new Vector.<PhysicalPoint>(_length);
            for (i = 0; i < _length; i++)
            {
                _pointVector[i] =  new PhysicalPoint(_pointOffset, i, spring, friction);
            }
        }
        //縦方向
        else
        {
            _pointOffset = _sourceH / 2;
            this.addEventListener(Event.ENTER_FRAME, verticalEnterFrameHandler);
            _length = _sourceW;
            //幅分のポイントデータ格納用
            _pointVector = new Vector.<PhysicalPoint>(_length);
            for (i = 0; i < _length; i++)
            {
                _pointVector[i] =  new PhysicalPoint(i,_pointOffset, spring, friction);
            }
        }
        
    }
    
    private function init(e:Event):void 
    {
        removeEventListener(Event.ADDED_TO_STAGE, init);
        this.addEventListener(Event.REMOVED_FROM_STAGE, removeFromStageHandler);
        
        //転写用のBitmapDataを生成
        _canvasBmd = new BitmapData(_sourceW,_sourceH);
        var _bm:Bitmap = new Bitmap(_canvasBmd);
        addChild(_bm);
    }
    
    private function removeFromStageHandler(e:Event):void 
    {
        removeEventListener(Event.REMOVED_FROM_STAGE, removeFromStageHandler);
        destroy();
    }
    //オブジェクトの削除
    public function destroy():void
    {
        this.removeEventListener(Event.ENTER_FRAME, horizonEnterFrameHandler);
        this.removeEventListener(Event.ENTER_FRAME, verticalEnterFrameHandler);
        
        _sourceBmd.dispose();
        _canvasBmd.dispose();
        
        for (var i:int = 0; i < pointVector.length; i++)
        {
            pointVector[i] = null;
        }
    }
    //横揺れ時のエンターフレーム処理
    private function horizonEnterFrameHandler(e:Event):void 
    {
        _canvasBmd.lock();
        _elasticSpeedPosition += _elasticSpeed;
        for (var i:int = 0,j:int = _elasticSpeedPosition; i < _sourceH; i++,j+= _elasticity)
        {
            //伸縮の計算
            var offsetPoisition:Number = _frequency * Math.sin(j * 3.141592 / 180 / 100);
            var v:int;
            var num:Number = (i + offsetPoisition);
            if (num > _sourceH) v = num - _sourceH;
            else if (num < 0) v = num + _sourceH;
            else v = num;
            
            //位置移動の計算
            var friction:Number = Math.sin( -Math.PI / 2 + Math.PI / (_target.y) * i)*.5 + .5;
            if (_target.y == 0) friction = 0;
            if (i > _target.y)
            {
                friction = Math.sin(Math.PI / 2 + Math.PI / (_sourceH - _target.y) * (i - _target.y))*.5 + .5;
            }
            if ( _target.y == 0) friction = 0;
            if ( _target.y == _sourceH) friction = 0;
            friction *= _friction;
            _pointVector[i].friction = friction;
            _pointVector[i].spring = spring;
            
            _pointVector[i].ax = _target.x - _pointVector[i].posX;
            
            _canvasBmd.copyPixels(_sourceBmd, new Rectangle(0, v, _copyRect, 1), new Point(-_startPoint +_pointVector[i].posX, i));
        }
        _canvasBmd.unlock();
    }
    //縦揺れ時のエンターフレーム処理
    private function verticalEnterFrameHandler(e:Event):void 
    {
        _canvasBmd.lock();
        _elasticSpeedPosition += _elasticSpeed;

        for (var i:int = 0,j:int = _elasticSpeedPosition; i < _sourceH; i++,j+= _elasticity)
        {
            //伸縮の計算
            var offsetPoisition:Number = _frequency * Math.sin(j * 3.141592 / 180 / 100);
            var v:int;
            var num:Number = (i + offsetPoisition);
            if (num > _sourceW) v = num - _sourceW;
            else if (num < 0) v = num + _sourceW;
            else v = num;
            
            //位置移動の計算
            var friction:Number = Math.sin( -Math.PI / 2 + Math.PI / (_target.x) * i)*.5 + .5;
            if (i > _target.x)
            {
                friction = Math.sin(Math.PI / 2 + Math.PI / (_sourceH - _target.x) * (i - _target.x))*.5 + .5;
            }
            if ( _target.x == 0) friction = 0;
            if ( _target.x == _sourceW) friction = 0;
            friction *= _friction;
            _pointVector[i].friction = friction;
            _pointVector[i].spring = spring;
            
            _pointVector[i].ay = _target.y - _pointVector[i].posY;
            
            _canvasBmd.copyPixels(_sourceBmd, new Rectangle(v, 0, 1, _copyRect), new Point(i,-_startPoint +_pointVector[i].posY));
        }    
        _canvasBmd.unlock();
    }
    
    public function get pointVector():Vector.<PhysicalPoint> { return _pointVector; }
    
    public function get friction():Number { return _friction; }
    
    public function set friction(value:Number):void 
    {
        _friction = value;
    }
    
    public function get spring():Number { return _spring; }
    
    public function set spring(value:Number):void 
    {
        _spring = value;
    }
    
    public function set frequency(value:int):void 
    {
        _frequency = value;
    }
    
    public function set elasticity(value:int):void 
    {
        _elasticity = value;
    }
    
    public function set elasticSpeed(value:int):void 
    {
        _elasticSpeed = value;
    }
    
    
}



class PhysicalPoint {
    private var _posX:Number = 0;
    private var _posY:Number = 0;
    private var _spring:Number = 0;
    private var _friction:Number;
    private var _vx:Number = 0;
    private var _vy:Number = 0;
    private var _ax:Number = 0;
    private var _ay:Number = 0;
    private var _gravityX:Number = 0;
    private var _gravityY:Number = 0;
    
    public function PhysicalPoint(posX:Number = 0, posY:Number = 0, spring:Number = .06, friction:Number = .8)
    {
        this._spring = spring;
        this._friction = friction;
        _posX = posX;
        _posY = posY;
    }
    
    public function get posX():Number {
        _ax = _ax * _spring;
        _vx += _ax;
        _vx += _gravityX;
        _vx *= _friction;
        _posX += _vx;
        return _posX;
    }
    public function get posY():Number {
        _ay = _ay * _spring;
        _vy += _ay;
        _vy += _gravityY;
        _vy *= _friction;
        _posY += _vy;
        return _posY;
    }
    
    public function set ax(value:Number):void 
    {
        _ax = value;
    }
    
    public function set spring(value:Number):void 
    {
        _spring = value;
    }
    
    public function set friction(value:Number):void 
    {
        _friction = value;
    }
    
    public function set ay(value:Number):void 
    {
        _ay = value;
    }
    
}