flash on 2011-5-31

by amdmamdma
♥0 | Line 58 | Modified 2011-06-03 14:36:02 | MIT License
play

ActionScript3 source code

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

package {
    import flash.geom.ColorTransform;
    import flash.filters.BlurFilter;
    import flash.utils.Proxy;
    import flash.events.Event;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Graphics;
    import flash.display.Sprite;
    import net.hires.debug.Stats;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            //デバッグ用
            //addChild(new Stats());
            //元画像生成
            var sp01:Sprite = new Sprite();
            var gr01:Graphics = sp01.graphics;
            for(var k:uint = 0; k < 100; k ++){
                gr01.beginFill(Math.random() * 0xffffff);
                gr01.drawRect(Math.random() * 400, Math.random() * 400, Math.random() * 100, Math.random() * 100);
                gr01.endFill();
            }
            var bd01:BitmapData = new BitmapData(sp01.width, sp01.height, true, 0x00000000);
            bd01.draw(sp01);
            //元画像表示用
            var bd02:BitmapData = bd01.clone();
            var bm02:Bitmap = new Bitmap(bd02);
            addChild(bm02);
            //エフェクト表示用
            var bd03:BitmapData = new BitmapData(sp01.width, sp01.height, true, 0x00000000);
            var bm03:Bitmap = new Bitmap(bd03);
            addChild(bm03);
            //フレーム監視開始
            addEventListener(Event.ENTER_FRAME, xFrame);
            //エフェクト対象行
            var nStart:int = 0;
            var nStop:uint = 0;
            
            //フレーム処理
            function xFrame(e:Event):void{
                //残像
                bd03.colorTransform(bd03.rect, new ColorTransform(1, 1, 1, 1, 0, 0, 0, -5) );
                //右方向
                var nLen:uint = bd01.width;
              for(var i:uint = 0; i < nLen; i ++){
                  //下方向
                    for(var j:uint = nStart; j < nStop; j ++){
                        //3分の1の確立で処理する
                        if(Math.floor(Math.random() * 3) == 1){
                            //変化量
                            var _vy:int = - Math.random() * 5;
                            //上にずらす
                            bd03.setPixel32(i, j + _vy, bd02.getPixel32(i, j));
                            bd03.setPixel32(i, j + _vy, bd03.getPixel32(i, j));
                            //元あった場所は透明で置き換え
                            bd02.setPixel32(i, j, 0x00000000);
                        }
                    }
                }
                //対象行移動
                if(nStop> 100){
                    nStart ++;
                }
                nStop ++;
                //リセット用
                if(nStop >= bd01.height){
                    nStart = 0;
                    nStop = 0;
                    bd02 = bd01.clone();
                    bm02.bitmapData = bd02;
                    bd03.fillRect(bd01.rect, 0x000000);
                }
            }
        }
    }
}