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

Archimedes And Fermat's Spiral

Archimedes & Fermat's Spiral examples.
/**
 * Copyright Matt_Wakeling ( http://wonderfl.net/user/Matt_Wakeling )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/cGEx
 */

package 
{
    // Import External Classes
    import flash.display.SpreadMethod;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
        
    
    // Reconfigure Stage Properties
    [SWF(width='465',height='465',backgroundColor='#000000',frameRate='30')]
    
    /**
    * Name          : Main 
    * Coded By      : Matt Wakeling
    * Date          : 29th April 2012
    * Description   : Main Class for the Application.
    *                 Example of Archimedes and Fermat Spiral using Polar Coordinates.
    *
    * @author Matt Wakeling
    */
    public class Main extends Sprite 
    {
        // Main Constructor
        public function Main()
        {
            // Constructor Code
            super();
            InitialiseMain();
        }

        // InitialiseMain Method
        private function InitialiseMain():void
        {
            if (stage)
                this.InitialiseStage();
            else addEventListener(Event.ADDED_TO_STAGE, this.InitialiseStage);
        }
        
        // InitialiseStage Method
        private function InitialiseStage(e:Event = null):void
        {
            removeEventListener(Event.ADDED_TO_STAGE, this.InitialiseStage);
                                                                   
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align     = StageAlign.TOP_LEFT;

            // Black Screen for Wonderfl Capture
            this.graphics.beginFill(0x000000,1);
            this.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
            this.graphics.endFill();
            
            displaySpiral(100, 100, "Archimedes");
            displaySpiral(365, 100, "Fermat");
            
        }
        
        // displayShape Method
        private function displaySpiral($x:int, $y:int, $type:String) :void
        {
            // $r = Radius
            // $a = Polar Angle or Azimuth
            
            var sprSprite:Sprite = new Sprite;
            
            sprSprite.graphics.clear();
            
            displayAxis(sprSprite);
            
            sprSprite.graphics.lineStyle(1, 0xFFFFFF);
                
            var $r:Number = 0;
            var $a:Number = 0;
            var $condense:Number = 60;
            var $reduction:Number = 60;
            var $iterations:uint = 10;
            
            for (var $s:Number = 1; $s <= 360; $s++)
            {
                if ($type == "Archimedes") $r = $a / $condense;
                if ($type == "Fermat") $r = ($reduction * Math.sqrt($a)) / $condense;
                
                if ($s == 1) movep($r, $a, sprSprite);
                drawp($r, $a, sprSprite);
                $a = $a + $iterations;
            }
                        
            sprSprite.x = $x;
            sprSprite.y = $y;
            
            addChild(sprSprite);
        }
        
                
        // displayAxis Method
        private function displayAxis($sprObject:Sprite) :void
        {
            $sprObject.graphics.lineStyle(1, 0xFFFFFF,0.5);
            $sprObject.graphics.moveTo(-60, 0);
            $sprObject.graphics.lineTo(60, 0);
            $sprObject.graphics.moveTo(0, -60);
            $sprObject.graphics.lineTo(0, 60);
            
            for (var $Axis:Number = -60; $Axis <= 60; $Axis = $Axis + 5)
            {
                $sprObject.graphics.moveTo(-2, $Axis);
                $sprObject.graphics.lineTo(2, $Axis);
                
                $sprObject.graphics.moveTo($Axis, -2);
                $sprObject.graphics.lineTo($Axis, 2);
            }
        }
        
        // movep Method
        private function movep($r:Number, $a:Number, $sprObject:Sprite) :void
        {
            $a = $a * Math.PI / 180;
            
            $sprObject.graphics.moveTo(($r * Math.cos($a)), ($r * Math.sin($a)));
        }
        
        // drawp Method
        private function drawp($r:Number, $a:Number, $sprObject:Sprite) :void
        {
            $a = $a * Math.PI / 180;
            
            $sprObject.graphics.lineTo(($r * Math.cos($a)), ($r * Math.sin($a)));
        }
        
    }
}