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

Grid

Get Adobe Flash player
by antalg 10 Jun 2012
    Embed
package {
    import flash.display.Bitmap;
    import flash.geom.Rectangle;
    import flash.display.BitmapData;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var _map:Array;        
        private const WIDTH:int = stage.stageWidth;
        private const HEIGHT:int = stage.stageHeight;
        private var tileW:int;
        private var tileH:int;
        private var W:int;
        private var H:int;      
        
        private var _canvas:BitmapData = new BitmapData(WIDTH, HEIGHT);
        
        // private var derp:Event
        
        public function FlashTest() {
            createMap(50,50);
            addChild(new Bitmap(_canvas));
            
            stage.addEventListener(Event.ENTER_FRAME, enterFrame);
        }
        
        private function createMap(w:int, h:int):void {
            W = w; H = h;
            var x:int, y:int;
            tileW = WIDTH/w;
            tileH = HEIGHT/h;
            
            _map = [];
            for(y = 0; y<h; y++) {
                _map.push([]);
                for(x = 0; x<w; x++) {
                    _map[y].push( (x + y)&1 );
                }
            }
        }
        
        private function setTile(x:int, y:int, n:int):void {
            var oldX:int = x, oldY:int = y;
            
            switch(n) {    // Get new coord
                case 0:
                    x = (oldX+1) % W;
                    break;
                case 1:
                    x = (oldX+W-1) % W;
                    break;
                case 2:
                    y = (oldY+1) % H;
                    break;
                case 3:
                    y = (oldY+H-1) % H;
                    break;
            }
            
            if(_map[x][y] == 0) {    // If new space free, move there
                _map[oldX][oldY] = 0
                _map[x][y] = 1;
            }
            /*else {
                _map[x][y] = 2;
            }*/

        }

        private var count:int = 0;
        
        private function enterFrame(e:Event):void {
            count++;
            if(count == 10) {
                count = 0;
                var x:int, y:int;
                
                _canvas.fillRect(_canvas.rect, 0xFF000000);
                
                for(y = 0; y<H; y++)
                    for(x = 0; x<W; x++)
                        if(_map[x][y] == 1)
                            setTile(x, y, Math.random()*4);
                
                for(y = 0; y<H; y++) {
                    for(x = 0; x<W; x++) {
                        var R:Rectangle = new Rectangle(x*tileW,y*tileH,tileW, tileH);
                        
                        var b:int = 255.0*(x+y)/(W+H-2);        
                        var color1:uint = (255<<24)|0      |(b<<8)|b;
                        var color2:uint = (255<<24)|(b<<16)|(b<<8)|0;
                        var color:uint = _map[x][y] == 1 ? color1 : color2;
                        
                        //if(_map[x][y] == 2) color = 0xFF000000;
                        
                        _canvas.fillRect(R, color);
                    }
                }
            }
        }
    }
}

var trace:Function = Wonderfl.log;