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

Simple Polygons using Polar Coordinates

Using Polar Coordinates polygon shapes can be quickly created for Flash Scripts.
/**
 * 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/oQD5
 */

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="0",frameRate="60")]
    
    /**
    * Name           : Main 
    * Coded By       : Matt Wakeling
    * Date           : 29th April 2012
    * Description    : Main Class for the Application.
    *                  Simple Polygon's 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();            
                    
            var $divisionofcircle:uint = 3;
            
            for (var $column:Number = 0; $column <= 3; $column++)
            {
                for (var $row:Number = 0; $row <= 3; $row++)
                {
                    displayShape(($row * 165) + 65, ($column * 165) + 65, 50, $divisionofcircle);
                    $divisionofcircle++;
                }
            }
            
        }
        
        // displayShape Method
        private function displayShape($x:int, $y:int, $r:uint, $divisionofcircle:uint) :void
        {
            // $r = Radius
            // $a = Polar Angle or Azimuth
            
            var sprSprite:Sprite = new Sprite;
            
            sprSprite.graphics.clear();
            
            displayAxis(sprSprite);
            
            sprSprite.graphics.beginFill(0xFFFF00, 0.5);
            sprSprite.graphics.lineStyle(2, 0xFFFFFF);
                    
            for (var $a:Number = 0; $a <= 360; $a = $a + (360 / $divisionofcircle))
            {
                if ($a == 0) movep($r, $a, sprSprite);
            
                drawp($r, $a, sprSprite);
            }
            
            sprSprite.graphics.endFill();
            
            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:int, $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:int, $a:Number, $sprObject:Sprite) :void
        {
            $a = $a * Math.PI / 180;
            
            $sprObject.graphics.lineTo(($r * Math.cos($a)), ($r * Math.sin($a)));
        }
        
    }
}