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

RasterTransition

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

RasterEffectのRasterImageクラスをちょっといじって流用
* http://wonderfl.net/c/lTDX
* 
*
* クリックしたY座標の位置を頂点にしてラスタースクロールします
*
* ※フルスクリーンだと表示イマイチ(手抜き)
*
*
/**
 * Copyright sakusan393 ( http://wonderfl.net/user/sakusan393 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8eKz
 */

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

/*
 * RasterEffectのRasterImageクラスをちょっといじって流用
 * http://wonderfl.net/c/lTDX
 * 
 *
 * クリックしたY座標の位置を頂点にしてラスタースクロールします
 *
 * ※フルスクリーンだと表示イマイチ(手抜き)
 *
 * */

package {
    import flash.events.MouseEvent;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.net.URLLoader;
    import flash.display.*;
    import flash.system.LoaderContext;
    import flash.text.TextField;
    
    [SWF(width="465", height="465", backgroundColor="0x0", frameRate="60")] 
    public class MediaRSSReader2 extends Sprite {
        private var _feed:String = "http://api.flickr.com/services/feeds/photos_public.gne?tags=Pablo Picasso&format=rss_200";
        private var media:Namespace = new Namespace("http://search.yahoo.com/mrss/");

        private var _loaderArray:Array = [];
        private var _loadCount:int;
        private var _maxCount:int;
        private var _sourceBmd:BitmapData;
        private var _W:int = 465;
        private var _H:int = 465;
        private var _point:Point;
        private var _currentPage:int;
        private var _left:Sprite;
        private var _right:Sprite;
        private var _imageNum:int;
        private var _tf:TextField;
        
        public function MediaRSSReader2() {
            
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            //_W = stage.stageWidth;
            //_H = stage.stageHeight;
            
            var ldr:URLLoader = new URLLoader;
            ldr.addEventListener(Event.COMPLETE, ldrCompleteHandler)
            
            ldr.load(new URLRequest(_feed));
            _tf = new TextField();
            _tf.textColor = 0xFFFFFF;
            _imageNum = 0;
            _tf.text = "image:loading...";
            addChild(_tf);
            _tf.x = 10;
            _tf.y = 10;
        }
        
        private function ldrCompleteHandler(e:Event):void 
        {
            var ldr:URLLoader = URLLoader(e.target);
            var xl : XMLList = XML(ldr.data)..media::content;
            var len : uint = xl.length();
            var urlArray:Array = [];
            for(var i : uint = 0;i < len;i++){
                if(xl[i].@height * xl[i].@width <= 1000 * 1000){
                    urlArray.push(xl[i].@url.toXMLString());
                }
            }
            
            
            ldr.removeEventListener(Event.COMPLETE, ldrCompleteHandler);
            //var xml:String = XML(ldr.data)..media::content.@url.toXMLString();
            //var array:Array = xml.split('\n');
            _maxCount = urlArray.length;
            _currentPage = (0 | _maxCount / 2);
            trace("_maxCount : " + _maxCount);
            if (_maxCount % 2 == 0) _maxCount -= 1;
            if (_maxCount > 15) _maxCount = 15;
            onImageLoaded(urlArray);
        }
        
        private function onImageLoaded($images:Array):void {
            var ldr:Loader;
            for (var i:int = 0; i < _maxCount; ++i) {
                ldr = new Loader;
                ldr.load(new URLRequest($images[i]), new LoaderContext(true) );
                _loaderArray.push(ldr);
                ldr.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
            }
        }
        
        private function completeHandler(e:Event):void 
        {
            _imageNum++;
            _tf.text = "image:" + _imageNum + " / "+ _maxCount;
            _loadCount++;
            if (_loadCount == _maxCount) setSourceBitmapData();
        }
        
        private function setSourceBitmapData():void
        {
            _point = new Point();

            _sourceBmd = new BitmapData(_W * _maxCount, _H, false, 0x0);
            var i:int;
            for (i = 0; i < _maxCount; i++)
            {
                var loader:Loader = _loaderArray[i];
                _sourceBmd.draw(_loaderArray[i], new Matrix(_W / loader.width, 0, 0, _H / loader.height, _W * i, 0));
                trace("_sourceBmd.height : " + _sourceBmd.height);
                trace("_sourceBmd.width : " + _sourceBmd.width);
            }
            _sourceBmd.height
            var img:RasterImage = addChild(new RasterImage(_sourceBmd, _point,.02,.93,5,2000,100)) as RasterImage;
            img.width
            trace("img.width : " + img.width);
            img.x = -_W*(0|_maxCount/2)
            
            stage.addEventListener(MouseEvent.CLICK, clickHandler);
            stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
            
            _left = new Sprite();
            _left.graphics.beginFill(0x0,.4);
            _left.graphics.moveTo(0, 0);
            _left.graphics.lineTo(80, 150);
            _left.graphics.lineTo(0, 300);
            _left.graphics.lineTo(0, 0);
            _left.x = _W - _left.width - 10;
            _left.y = _H / 2 - _left.height / 2;
            addChild(_left).visible = false;
            _right = new Sprite();
            _right.graphics.beginFill(0x0,.4);
            _right.graphics.moveTo(80, 0);
            _right.graphics.lineTo(0, 150);
            _right.graphics.lineTo(80, 300);
            _right.graphics.lineTo(80, 0);
            addChild(_right).visible = false;
            _right.x = 10;
            _right.y = _H / 2 - _right.height / 2;
        }
        
        private function clickHandler(e:MouseEvent):void 
        {
                trace("mouseX : " + mouseX);
            if (mouseX > _W / 2)
            {
                if (_currentPage == _maxCount-1) return;
                _currentPage++;
            }
            else
            {
                if (_currentPage == 0) return;
                _currentPage--;
            }
            _point.x = 465 * (_currentPage)+ 465/2
            _point.y = mouseY;
        }
        
        private function enterFrameHandler(e:Event):void 
        {
            if (mouseX < _W / 2)
            {
                _right.visible = false;
                _left.visible = false;
                 if (_currentPage != 0)  _right.visible = true;
            }
            else
            {
                _left.visible = false;
                if (_currentPage != _maxCount - 1)_left.visible = true;
                _right.visible = false;
            }
        }
    }
}
import flash.events.Event;
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);
        _canvasBmd.copyPixels(_sourceBmd, new Rectangle(0, 0, _sourceBmd.width, _sourceBmd.height), new Point());
        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/ (_target.y) * i)*.2 + .8;
            if (_target.y == 0) friction = 0;
            if (i > _target.y)
            {
                friction = Math.cos(Math.PI / 2/(_sourceH - _target.y) * (i - _target.y))*.2 + .8;
            }
            if ( _target.y == 0) 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;
    }
    
    
}


import flash.display.*;
import flash.events.TimerEvent;

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;
    }
}