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 2011-5-6

http://levitated.net/daily/levInvaderFractal.html
Get Adobe Flash player
by bongiovi015 07 May 2011
/**
 * Copyright bongiovi015 ( http://wonderfl.net/user/bongiovi015 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/44yE
 */

package {
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.filters.ColorMatrixFilter;
    import flash.filters.DropShadowFilter;
    import flash.geom.ColorTransform;
    import flash.geom.Point;
    import flash.geom.Rectangle;
    import caurina.transitions.Tweener;

    
    public class FlashTest extends Sprite {
        public static const THRESHOLD : int = 20000;
        
        public static const MIN_SCALE : Number = .2;
        public static const W : int = 465;
        public static const H : int = 465;
        public static const RECT : Rectangle = new Rectangle(0, 0, W, H);
        public static const RED : ColorMatrixFilter = new ColorMatrixFilter( [0, 0, 0, 0, 215,
                                                                                              0, 0, 0, 0, 0,
                                                                                              0, 0, 0, 0, 0,
                                                                                              0, 0, 0, 1, 0]);
        
        public var MAX_SCALE : Number = 2.5;
        private var __bmpdFilled : BitmapData = new BitmapData(W, H, true, 0x00000000);
        private var __bmpdTest : BitmapData = new BitmapData(W, H, true, 0x00000000);
        private var __scale : Number = 0;
        private var __pos : Point;
        private var __first : Boolean = true;
        
        public function FlashTest() {
            stage.addEventListener(MouseEvent.CLICK, reset);
            stage.addEventListener(Event.ENTER_FRAME, __loop);
            filters = [new DropShadowFilter(3, 45, 0, .35, 6, 6, 1, 3)];
        }
        
        public function reset(e:Event=null) : void {
            __bmpdFilled.fillRect(RECT, 0);
            while(numChildren>0) removeChildAt(0);
            __first = true;
            MAX_SCALE = 2.5;
            
            stage.removeEventListener(Event.ENTER_FRAME, __loop);
            stage.addEventListener(Event.ENTER_FRAME, __loop);
        }
        
        
        private function __loop(e:Event) : void {
            var i : int = 0;
            const ITERATION:int = 5;
            while(i++<ITERATION) render();
            
            if(__bmpdFilled.histogram()[3][0] < THRESHOLD){
                stage.removeEventListener(Event.ENTER_FRAME, __loop);
            }
        }
        
        
        public function render() : void {
            __scale = MIN_SCALE;
            var tx:Number, ty:Number;
            const MAX_TRIES : int = 100;
            var numTry : int = 0;
            do {
                tx = Math.floor(Math.random() * W / Invader.WIDTH / MIN_SCALE) * Invader.WIDTH * MIN_SCALE;
                ty = Math.floor(Math.random() * H / Invader.WIDTH / MIN_SCALE) * Invader.WIDTH * MIN_SCALE;
                numTry ++;
                if(numTry > MAX_TRIES) return;
            } while (__bmpdFilled.getPixel32(tx, ty) != 0x00000000 || __bmpdFilled.hitTest(new Point, 255, new Rectangle(tx, ty, Invader.WIDTH * __scale, Invader.WIDTH * __scale)));
            
            
            while( !__bmpdFilled.hitTest(new Point, 255, new Rectangle(tx, ty, Invader.WIDTH * __scale, Invader.WIDTH * __scale) )  && __scale < MAX_SCALE){
                __scale += .05;
            }
            
            __scale -= 0.05;
            
            __bmpdFilled.fillRect(new Rectangle(tx, ty, Invader.WIDTH * __scale, Invader.WIDTH * __scale), 0xFFFFFFFF);
            
            var invader:Invader = new Invader(0x000000);
            addChild(invader);
            invader.x = tx;
            invader.y = ty;
            invader.scaleX = invader.scaleY = __scale;
            invader.alpha = 0;
            Tweener.addTween(invader, {time:.5, transition:"easeOutSine", alpha:1});

            
            if(__first && (tx + Invader.WIDTH * __scale) < stage.stageWidth && (ty + Invader.WIDTH * __scale) < stage.stageHeight ) {
                invader.filters = [RED];
                __first = false;
                MAX_SCALE = 1.8;
            }
        }
    }
}



import flash.display.BitmapData;
import flash.display.Sprite;


class Invader extends Sprite {
    
    public static const W : int = 10;
    public static const MARGIN : int = 3;
    public static const WIDTH : int = W * 5 + MARGIN * 2;
    
    public var color : uint;
    private var __ary : Array = [];
    
    public function Invader(color:uint) : void {
        this.color = color;
        __init();
    }
    
    
    private function __init() : void {
        var i:int=0, j:int=0;
        var tx:Number, ty:Number;
        
        for(i=0; i<2; i++) {
            for(j=0; j<5; j++) {
                tx = i*W + MARGIN;
                ty = j*W + MARGIN;
                if( Math.random() > .5 ) {
                    graphics.beginFill(color, 1);
                    graphics.drawRect(tx, ty, W, W);
                    graphics.endFill();
                    
                    graphics.beginFill(color, 1);
                    graphics.drawRect(W*4 - tx + MARGIN*2 , ty, W, W);
                    graphics.endFill();
                }
            }
        }
        
        
        for(j=0; j<5; j++) {
            tx = 2*W + MARGIN;
            ty = j*W + MARGIN;
            if( Math.random() > .5 ) {
                graphics.beginFill(color, 1);
                graphics.drawRect(tx, ty, W, W);
                graphics.endFill();
            }
        }
        
    }
    
}