Beautifl - Flash Gallery

Thumbnail : [朝ワン]ぐにゃぐにゃ。
[朝ワン]ぐにゃぐにゃ。
bkzen 2009-08-27 MIT License

再生するにはFlash Playerが必要です。デスクトップのブラウザでご覧ください。

package  
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;
    import flash.filters.DisplacementMapFilter;
    import flash.filters.DisplacementMapFilterMode;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.utils.ByteArray;
    import net.hires.debug.Stats;
    
    /**
     *
     * ぐにゃぐにゃ
     * さぁなんという文字が出てくるでしょうか。
     * @author jc at bk-zen.com
     */
    [SWF (backgroundColor = "0x0", frameRate = "30", width = "465", height = "465")]
    public class Asawon8 extends Sprite
    {
        private var bmd: BitmapData;
        private var txtBmd: BitmapData;
        private var noise: BitmapData;
        private var mw: int;
        private var mh: int;
        private var seed:int;
        private var point1:Point;
        private var point2:Point;
        private var points:Array;
        private var txt:TextField;
        private var txtMatrix: Matrix;
        private var dispf:DisplacementMapFilter;
        private var basePoint:Point;
        private var txtBmp:Bitmap;
        private var colorTf:ColorTransform;
        private var blur:BlurFilter;
        
        public function Asawon8() 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e: Event = null): void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            //
            addChild(new Bitmap(bmd = new BitmapData(465, 465, true, 0x0)));
            noise = bmd.clone();
            noise.perlinNoise(mw = 465 >> 2, mh = 465 >> 2, 2, seed = Math.random() * 0xFFFF, false, false, 3);
            addChild(new Stats());
            points = [point1 = new Point(), point2 = new Point()];
            basePoint = new Point();
            var byte: ByteArray = new ByteArray();
            var str: String = "78 da 4b ca d6 ad 4a cd d3 4b ce cf 5 0 14 f 3 b5";
            var strArr: Array = str.split(" ");
            while (strArr.length > 0)
            {
                byte.writeByte(parseInt(strArr.shift(), 16));
            }
            byte.uncompress();
            txt = new TextField();
            txt.text = byte.readUTFBytes(byte.length);
            txt.textColor = 0xFFFFFF;
            txt.autoSize = TextFieldAutoSize.LEFT;
            txtMatrix = new Matrix(8, 0, 0, 8, (465 - txt.width * 8) / 2, (465 - txt.height * 8) / 2);
            txtBmp = new Bitmap(txtBmd = bmd.clone());
            txtBmd.draw(txt, txtMatrix);
            dispf = new DisplacementMapFilter(noise, basePoint, BitmapDataChannel.RED, BitmapDataChannel.GREEN, 500, 500, DisplacementMapFilterMode.WRAP);
            txtBmp.filters = [dispf];
            colorTf = new ColorTransform(1, 1, 1, 1, - 4, - 1, - 1);
            blur = new BlurFilter();
            addEventListener(Event.ENTER_FRAME, loop);
        }
        
        private function loop(e: Event ): void 
        {
            point1.x += 2;
            point2.y += 2;
            noise.perlinNoise(mw, mh, 2, seed, false, true, 3, false, points);
            bmd.lock();
            bmd.draw(txtBmp);
            bmd.colorTransform(bmd.rect, colorTf);
            bmd.applyFilter(bmd, bmd.rect, basePoint, blur);
            bmd.unlock();
            if (dispf.scaleX > 0)
            {
                dispf.scaleX --;
                dispf.scaleY --;
                txtBmp.filters = [dispf];
            }
            
        }
        
    }
}