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

flash on 2009-12-13

Get Adobe Flash player
by uwi 14 Dec 2009
/**
 * Copyright uwi ( http://wonderfl.net/user/uwi )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/jRRM
 */

package {

import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
import flash.filters.*;

public class Main extends Sprite
{
    static private const N:uint = 50;
    
    private function _init():void
    {
        _debug(
            "465x465のBitmapDataで各テスト " + N + " 回処理させた計算結果 [単位 : ミリ秒]\n" +
            "(誤差は多少生じます)\n"
        );
        
        var W : int = 465;
        var H : int = 465;
        
        var src : BitmapData = new BitmapData(W, H, false, 0x000000);
        var dst : BitmapData = new BitmapData(W, H, false, 0x000000);
        var ct : ColorTransform = new ColorTransform(0.99, 0.99, 0.99, 0.99, 20, 20, 20, 20);
        var cmf : ColorMatrixFilter = new ColorMatrixFilter([
            0.99, 0, 0, 0, 20,
            0, 0.99, 0, 0, 20,
            0, 0, 0.99, 0, 20,
            0, 0, 0, 0.99, 20
            ]);
        var bf : BlurFilter = new BlurFilter(4, 4, 1);
        var P0 : Point = new Point();
        src.lock();
        dst.lock();
        var bmp : Bitmap = new Bitmap(src);
        src.noise(0);
         
        _measure("べーす", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
            }
        });
        
        /*
        _measure("perlinNoise", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.floodFill(0, 0, 0xffffff);
                dst.perlinNoise(0, 0, 1, i, false, false);
            }
        });
        */
        
        _measure("noise", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.floodFill(0, 0, 0xffffff);
                dst.noise(i);
            }
        });
        
        _measure("histogram", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.floodFill(0, 0, 0xffffff);
                dst.histogram();
            }
        });
        
        _measure("floodFill", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.floodFill(0, 0, 0xffffff);
                dst.fillRect(src.rect, 0);
            }
        });
        
        _measure("blurFilter(4, 4, 1)", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.applyFilter(src, src.rect, P0, bf);
            }
        });
        
        _measure("copyChannel", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.copyChannel(src, src.rect, P0, 4, 4);
            }
        });
        
        _measure("colorTransform", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.colorTransform(src.rect, ct);
            }
        }); 
        
        _measure("ColorMatrixFilter", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.applyFilter(src, src.rect, P0, cmf);
            }
        });
        /*
        _measure("clone", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst = src.clone();
//                dst.dispose();
            }
        });
        */
        
        _measure("threshold", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.threshold(src, src.rect, P0, ">=", 0, 0xffffff);
            }
        });
        
        _measure("draw", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.draw(bmp);
            }
        });
        
        _measure("copyPixels", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.copyPixels(src, src.rect, P0);
            }
        });
        
        _measure("fillRect", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.fillRect(src.rect, 0xffffff);
            }
        });
        
        _measure("setPixel", function ():void
        {
            for (var i:uint = 0; i < N; i++) {
                dst.fillRect(src.rect, 0);
                dst.setPixel(i, i, i);
            }
        });
        
        _debug("\n結果については言及しませんので, 各自ご判断ください.");
    }
    
    private var _field:TextField;
    private var _time:uint;
    
    public function Main():void
    {
        _setup();
        _init();
    }
    
    private function _measure(title:String, func:Function, ...params):void
    {
        _time = getTimer();
        func.apply(null, params);
        _time = getTimer() - _time;
        
        _debug("[ " + title + " ] --> " + _time + " ms");
    }
    
    private function _debug(log:String):void
    {
        _field.appendText(log + "\n");
    }
    
    private function _setup():void
    {
        _field = new TextField();
        _field.width = stage.stageWidth - 40;
        _field.height = stage.stageHeight - 60;
        _field.x = 20;
        _field.y = 60;
        _field.multiline = true;
        _field.wordWrap = true;
        
        var format:TextFormat = _field.defaultTextFormat;
        format.font = "_sans";
        _field.defaultTextFormat = format;
        
        addChild(_field);
        
        var button:Sprite = new Sprite();
        button.graphics.lineStyle(1, 0xBBBBBB);
        button.graphics.beginFill(0xEEEEEE);
        button.graphics.drawRoundRect(0, 0, 100, 20, 5, 5);
        button.graphics.endFill();
        
        addChild(button);
        
        button.x = 20;
        button.y = 20;
        button.mouseChildren = false;
        button.buttonMode = true;
        
        var field:TextField = new TextField();
        field.width = 100;
        field.height = 20;
        field.htmlText = "<p align='center'><font face='_sans'>再計算</span></p>";
        
        button.addChild(field);
        
        button.addEventListener(MouseEvent.CLICK, function ():void
        {
            _field.text = "";
            _init();
        });
    }
}

}