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

forked from: flash on 2010-11-24

对http://wonderfl.net/c/bPbw做了点改动
@author sliz http://game-develop.net/blog/
Get Adobe Flash player
by bradsedito 25 Nov 2010
/**
 * Copyright bradsedito ( http://wonderfl.net/user/bradsedito )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/p6Ow
 */

// forked from starlizhi's flash on 2010-11-24
package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.geom.Point;

    /**
     * 对http://wonderfl.net/c/bPbw做了点改动
     * @author sliz http://game-develop.net/blog/
     */
    public class FlashTest extends Sprite {
        public function FlashTest(){
            w = 400;
            vectormap = new BitmapData(w, w);

            bmpdata = new BitmapData(w, w, false, 0);
            addChild(new Bitmap(bmpdata));

            stage.addEventListener(Event.ENTER_FRAME, reset);

        }

        private var vectormap:BitmapData; 
        private var bmpdata:BitmapData;
        private var oy:int = 0;
        private var w:int;
 
        private function reset(e:Event):void {
            vectormap.perlinNoise(w * .5, w * .5, 1, 1, true, true, 16, true, [new Point(0, oy++)]);

            bmpdata.fillRect(bmpdata.rect, 0);

            for (var y:int = 0; y < vectormap.height; y++){
                for (var x:int = 0; x < vectormap.width; x++){
                    var px:uint = vectormap.getPixel(x, y);
                    var r:int = px >> 16 & 0xFF;
                    var g:int = px >> 8 & 0xFF;
                    var b:int = px & 0xFF;

                    var tx:int = x + (g / 0xFF - .5) * w;
                    var ty:int = y + (b / 0xFF - .5) * w;

                    if (ty < 0 || ty >= bmpdata.height || tx < 0 || tx >= bmpdata.width)
                        continue;
                    var col:uint = bmpdata.getPixel(tx, ty);
                    col += 0x010101 * (int)(r * .2);
                    if (col > 0xFFFFFF)
                        col = 0xFFFFFF;
                    bmpdata.setPixel(tx, ty, col);
                }
            }

        }
    }
}