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

CircleFractal - ioError 2038 ?

Use A, S, Z, X to change values
Get Adobe Flash player
by WLAD 06 Feb 2016
/**
 * Copyright WLAD ( http://wonderfl.net/user/WLAD )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/qgAg
 */

package {
    import flash.display.Sprite;
    import flash.events.KeyboardEvent;
    import com.adobe.images.JPGEncoder;
    import flash.display.BitmapData;
    import flash.utils.ByteArray;
    import flash.net.FileReference;
    import com.adobe.images.PNGEncoder;
    import flash.geom.Matrix;
    import flash.geom.Rectangle;
    import flash.geom.Point;
    import flash.system.Security;
    import flash.text.TextField;
    import flash.display.StageQuality;
    import flash.filters.DropShadowFilter;
    
    [SWF(width="600", height="600", frameRate="24", backgroundColor="0x000000")]
    public class CircleFractal extends Sprite
    {
        private var depth:int = 2;
        private var radius:int =  80;
        
        public function CircleFractal()
        {    
            stage.quality = 'low';
            stage.frameRate = 24;
            stage.align = 'tl';
            stage.scaleMode = 'noScale';
            
            Security.allowInsecureDomain( '*' );
            
            var c:Circle = new Circle();
            addChild( c );
            
            var tf:TextField = new TextField();
            tf.textColor = 0xFFFFFF;
            tf.autoSize = 'left';
            tf.selectable = false;
            tf.scaleX = tf.scaleY = 1.5;
            tf.filters = [ new DropShadowFilter( 0,0,0,1,  7,7,4 ) ];
            tf.alpha = 0.8;
            addChild( tf );
            
            
            c.x = stage.stageWidth / 2;
            c.y = stage.stageHeight / 2;
            
            graphics.beginFill(0);
            graphics.drawRect(0, 0, c.x * 2, c.y * 2);
            graphics.endFill();
            
            var mp:Point = new Point();
            var mx:Number = 0;
            var my:Number = 0;
            
            
            stage.addEventListener('mouseDown', function(e:*):void {
                    mp = new Point( 
                          stage.mouseX / stage.stageWidth - 0.5
                        , stage.mouseY / stage.stageHeight - 0.5 
                    );
            });
            
            var fileSaveError:Function = function( e:* ):void
            {
                var msg:String = e.type + " : " + e.text;
                
                c.visible = false;
                tf.text = msg;  
            };
            
            var file:FileReference = new FileReference();
            file.addEventListener('ioError', fileSaveError );
            file.addEventListener('securityError', fileSaveError );
            
            stage.addEventListener('rightMouseDown', function(e:*):void {
               
               var bitmapData:BitmapData = new BitmapData( stage.stageWidth * 2, stage.stageHeight * 2, true, 0x00000000 );
               
               c.scaleX = c.scaleY = 2;
               
               bitmapData.drawWithQuality( c, new Matrix( 1, 0,0, 1, stage.stageWidth, stage.stageHeight ) , null, null, null, false, StageQuality.BEST  );
               
               c.scaleX = c.scaleY = 1;
               
                var name:String = "F=" + mx.toFixed(3) + "_S=" + my.toFixed(3) + "_D=" + depth + "_R=" + radius;
                name += ".png";
                
               var jpgEncoder:JPGEncoder = new JPGEncoder( 80 );
                
               var byteArray:ByteArray = 
                   // PNGEncoder.encode(bitmapData);
                   jpgEncoder.encode( bitmapData );
               
               file.save( byteArray , name );
               
               // Test
               //c.visible = false;
               //graphics.clear();
               //graphics.beginBitmapFill( bitmapData, new Matrix( 0.5, 0, 0, 0.5)  );
               //graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
               //graphics.endFill();
            });
            
            addEventListener('enterFrame', function(e:*= null):void
            {
                if( c.visible == false ) return;
                
                mx = stage.mouseX / stage.stageWidth;
                mx = ( mp.x + mx  - .5 ) * 6;    
                if ( Math.abs( mx ) < 0.15 ) mx = 0.15 * (mx>0?1:-1);
                
                my = stage.mouseY / stage.stageHeight;
                my = ( mp.y + my - .5 ) * 6;
                
                tf.text = "Mouse:\n\t(F)Diff:\t" + mx.toFixed(3) + "\n\t(S)Dist:\t" +  my.toFixed(3);
                tf.appendText("\n\nMouse Zero:\n\tX: " + mp.x.toFixed(3) + "\n\tY: " + mp.y.toFixed(3) );
                tf.appendText("\n\nKeys [A/S] (D)Depth: " + depth);
                tf.appendText("\nKeys [Z/X] (R)Radius: " + radius);
                
                c.draw(radius, mx, my, depth);
            });
            
            stage.addEventListener('keyDown', function(e:KeyboardEvent):void
            {
                switch(e.keyCode)
                {
                    default: case 65: /*A*/ 
                        if ( depth < 10 ) depth ++;
                    break;
                    case 83: /*S*/ 
                        if ( depth > 0 ) depth --;
                    break;
                    case 90: /*Z*/
                        if ( radius < 220 ) radius ++;
                    break;
                    case 88: /*X*/
                        if ( radius > 5 ) radius --;
                    break;
                }
            });
        }
        
        
    }
    
}

import flash.display.Sprite;

class Circle extends Sprite
{
    private var rDist:Number;
    private var rDiff:Number;
    private var radius:Number;
    
    
    public function Circle( ) {}
    
    public function draw( radius:Number = 80, rDiff:Number = 2, rDist:Number = 2, depth:int = 4 ):void
    {
        this.radius = radius;
        this.rDiff = rDiff;
        this.rDist = rDist;
        
        graphics.clear();
        graphics.beginFill(0x00FF00);
        graphics.drawCircle(0, 0, radius);
        
        drawCircles( 0, 0, radius, depth );
    }
    
    private function drawCircles( x:Number, y:Number, radius:Number, depth:int = 0 ):void
    {
        var r_2:Number = radius / rDiff;
        var r3:Number = radius * rDist;
        
        var cx:Number, cy:Number;
        
        
        cx = x + r3;    cy = y;                drawCircle( cx, cy, r_2, depth );
        cx = x + -r3;    cy = y;                drawCircle( cx, cy, r_2, depth );
        cx = x;            cy = y + r3;        drawCircle( cx, cy, r_2, depth );
        cx = x;            cy = y -r3;            drawCircle( cx, cy, r_2, depth );
        
    }
    
    private function drawCircle( x:Number, y:Number, r:Number, depth:Number = 0 ):void
    {
        graphics.drawCircle(x, y, r);
        if ( depth > 0 ) drawCircles( x, y, r, depth - 1 );
    }
}