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

ton's Star Julia for impatient

Get Adobe Flash player
by makc3d 11 Mar 2009
// forked from ton's Star Julia
package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.TextEvent;
    import flash.filters.BlurFilter;
    import flash.text.TextField;
    
    [SWF(width=465, height=465, frameRate=120, backgroundColor=0)]
    public class StarJulia extends Sprite 
    {
        private const SIZE:int  = (stage.stageWidth < stage.stageHeight)? stage.stageWidth : stage.stageHeight;
        private const SCALE:Number = SIZE / 6;
        private const CENTER:Number = SIZE / 2;
        private const T:int = Math.floor(Math.random() * 3);
        
        private var _x:Number = 0.5;
        private var _y:Number = 0;
        private var x1:Number;
        private var y1:Number;
        private var xa:Number;
        private var ya:Number;
        private var r:Number;
        private var w:Number = 0;
        private var s:Number;
        
        private var bmd:BitmapData = new BitmapData(SIZE, SIZE, false, 0);
        private var blur:BlurFilter = new BlurFilter(1.4, 1.4, 2);
        public function StarJulia():void 
        {
            addChild(new Bitmap(bmd));
            var txt:TextField = new TextField();
            txt.textColor = 0xffffff;
            txt.text = "type : " + T;
            addChild(txt);
            addEventListener(Event.ENTER_FRAME, onEnterFrameHandlerFast);
        }

        private function onEnterFrameHandlerFast (e:Event):void
        {
            bmd.lock ();
            for (var boost:int = 0; boost < 10000; boost++)
                onEnterFrameHandler (e);
            //bmd.applyFilter (bmd, bmd.rect, bmd.rect.topLeft, blur);
            bmd.unlock ();
        }
        
        private function onEnterFrameHandler(e:Event):void 
        {
            switch(T) {
                case 0:
                    xa = -4 * _x + Math.cos(4 * w);
                    ya = -4 * _y + Math.sin(4 * w);
                    break;
                case 1:
                    xa = -4 * _x + 1;
                    ya = -4 * _y;
                    break;
                case 2:
                    xa = -4 * _x + Math.cos(w);
                    ya = -4 * _y + Math.sin(w);
                    break;
            }
            r = Math.sqrt(xa * xa + ya * ya);
            w = Math.atan2(ya, xa);
            
            switch(T) {
                case 0:
                    if (Math.random() < 0.5) {
                        x1 = -Math.cos(w) - Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 = -Math.sin(w) + Math.sqrt(r) * Math.sin(w / 2) / 2;
                    }else {
                        x1 = -Math.cos(w) + Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 = -Math.sin(w) - Math.sqrt(r) * Math.sin(w / 2) / 2;                        
                    }
                    break;
                case 1:
                    s = (Math.random() < 0.5) ? 1: -1;
                    if (Math.random() < 0.5) {
                        x1 = -s * Math.cos(w) - Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 =  s * Math.sin(w) - Math.sqrt(r) * Math.sin(w / 2) / 2;
                    }else {
                        x1 = -s * Math.cos(w) + Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 = s * Math.sin(w) + Math.sqrt(r) * Math.sin(w / 2) / 2;
                    }
                    break;
                case 2:
                    if (Math.random() < 0.5) {
                        x1 = - Math.cos(2 * w) - Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 = -Math.sin(2 * w) + Math.sqrt(r) * Math.sin(w / 2) / 2;
                    }else {
                        x1 = -Math.cos(2 * w) + Math.sqrt(r) * Math.cos(w / 2) / 2;
                        y1 = -Math.sin(2 * w) - Math.sqrt(r) * Math.sin(w / 2) / 2;
                    }
                    break;
            }

            // pre-calc ints to get stable pattern
            _x = x1; var __x:int = _x * SCALE;
            _y = y1; var __y:int = _y * SCALE;
            bmd.setPixel(__x + CENTER, __y + CENTER,
                (__x * __x + __y * __y)/(SCALE * SCALE)*0x1400);
        }
        
    }
    
}