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 2010-11-24

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

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;
	import flash.utils.ByteArray;
	import net.hires.debug.Stats;

    /**
     * 对http://wonderfl.net/c/bPbw做了点改动
     * @author sliz http://game-develop.net/blog/
     */
	[SWF(frameRate=60,width=465,height=465)]
    public class FlashTest extends Sprite {
        public function FlashTest(){
            w = 200;
            vectormap = new BitmapData(w, w,false,0xff0000);

            bmpdata = new BitmapData(w, w, false, 0);
			bytes2 = bmpdata.getPixels(bmpdata.rect);
			vs = bmpdata.getVector(bmpdata.rect);
			var image:Bitmap = new Bitmap(bmpdata);
            addChild(image);
			//image.width = image.height = 400;

            stage.addEventListener(Event.ENTER_FRAME, reset);
			addChild(new Stats);
        }

        private var vectormap:BitmapData;
        private var bmpdata:BitmapData;
        private var oy:int = 0;
        private var w:int;
		
		private var bytes2:ByteArray;
		private var vs:Vector.<uint>;

        private function reset(e:Event):void {
            vectormap.perlinNoise(w * .5, w * .5, 3, 1, false, true, 7, false, [new Point(0, oy++)]);
			
			/*bytes2.clear();
			bytes2.length = w * w * 4;*/
			vs = new Vector.<uint>(w*w);
			
			var bytes:ByteArray = vectormap.getPixels(bmpdata.rect);
			
            for (var y:int = 0; y < w; y++){
                for (var x:int = 0; x < w; x++){
                    var bi:int = (y * w + x) * 4+1;
					var r:int = bytes[bi++];//px >> 16 & 0xFF;
                    var g:int = bytes[bi++];//px >> 8 & 0xFF;
                    var b:int = bytes[bi];//px & 0xFF;

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

                    if (ty < 0 || ty >= w || tx < 0 || tx >= w)
                        continue;
					
					/*bi = (ty * w + tx) * 4 + 1;
					var col:uint = bytes2[bi];
					col += r * .2;
					if (col > 0xff) col = 0xff;
					bytes2[bi++] = bytes2[bi++] = bytes2[bi] = col;*/
					
					bi = ty * w + tx;
					var col:uint = vs[bi];
					col += 0x10101 * int(r * .2);
					if (col > 0xffffff) col = 0xffffff;
					vs[bi] = col;
                }
            }
			bmpdata.lock();
			//bmpdata.setPixels(bmpdata.rect, bytes2);
			bmpdata.setVector(bmpdata.rect, vs);
			bmpdata.unlock();
        }
    }
}