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

forked from: 円の大きさと分割数

/**
 * Copyright shohei909 ( http://wonderfl.net/user/shohei909 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pGRw
 */

// forked from zahir's 円の大きさと分割数
package {
    import com.bit101.components.Label;
    import flash.display.GraphicsStroke;
    import flash.display.Shape;
    import flash.events.KeyboardEvent;
    import flash.text.TextField;
    import flash.display.GraphicsSolidFill;
    import flash.display.IGraphicsData;
    import flash.display.Graphics;
    import flash.events.Event;
    import flash.display.GraphicsPath;
    import flash.display.Sprite;
    
    import com.bit101.components.NumericStepper;
    import com.bit101.components.CheckBox;
    
    [SWF(width="465", height="465")]
    public class Main extends Sprite {
        private var fill:GraphicsSolidFill;
        private var fill2:GraphicsSolidFill;
        private var stroke:GraphicsStroke;
        private var stroke2:GraphicsStroke;
        
        private var sizeStepper:NumericStepper;
        private var lengthStepper:NumericStepper;
        private var thicknessStepper:NumericStepper;
        private var polyCheck:CheckBox;
        
        private var s:Shape;
        
        public function Main() {
            
            addChild( (s = new Shape()) );
            
            new Label(this, 0, 0, "size :: ");
            sizeStepper = new NumericStepper( this , 30, 0, draw);
            new Label(this, 130, 0, "length :: ");
            lengthStepper = new NumericStepper( this, 170, 0, draw);
            new Label( this, 270, 0, "thickness :: ");
            thicknessStepper = new NumericStepper( this, 325, 0, draw );
            polyCheck = new CheckBox( this, 0, 30, "polygon", draw );
            polyCheck.selected = true;
            
            sizeStepper.maximum = 465;
            sizeStepper.minimum = 1;
            sizeStepper.value = 100;
            
            lengthStepper.maximum = 360;
            lengthStepper.minimum = 3;
            lengthStepper.value = 8;
            
            thicknessStepper.maximum = 50;
            thicknessStepper.minimum = 0;
            thicknessStepper.value = 2;
            
            fill = new GraphicsSolidFill(0x666666);
            fill2 = new GraphicsSolidFill(0xFF6666);
            stroke = new GraphicsStroke(1);
            stroke.fill = new GraphicsSolidFill(0x0);
            
            draw();
        }
        private function draw(e:Event = null):void
        {
            var g:Graphics = s.graphics;
            stroke.thickness = thicknessStepper.value;
            g.clear();
            if(polyCheck.selected){g.drawGraphicsData(new <IGraphicsData>[ fill,stroke, getPath(0,0,sizeStepper.value) ]);}
            g.drawGraphicsData(new <IGraphicsData>[ fill2,stroke, getPath2(0,0,sizeStepper.value) ]);
            //s.width = s.height = 465;
            s.x = s.y = 465 >> 1;
        }
        public function appendPath( path:GraphicsPath, cx:Number, cy:Number, r:Number):void
        {
            var n:Number = 0;
            var len:int = lengthStepper.value;
            var d:Vector.<Number> = path.data;
            var dl:int = d.length;
            var c:Vector.<int> = path.commands;
            var cl:int = c.length;
            var _cl:int = cl;
            
            n = 360 / len;
            for (var i:int = 0; i <= len; i++ )
            {
                var rad:Number = 0.01745 * ((n * i) % 360);
                c[cl++] = 2;
                d[dl++] = Math.cos( rad ) * r + cx;
                d[dl++] = Math.sin( rad ) * r + cy;
            }
            c[_cl] = 1;
        }
        public function getPath(cx:Number, cy:Number, r:Number):GraphicsPath
        {
            var path:GraphicsPath = new GraphicsPath( new <int>[], new <Number>[] );
            appendPath( path, cx, cy, r );
            return path;
        }
        
        public function appendPath2( path:GraphicsPath, cx:Number, cy:Number, r:Number):void
        {
            var n:Number = 0;
            var len:int = lengthStepper.value;
            var d:Vector.<Number> = path.data;
            var dl:int = d.length;
            var c:Vector.<int> = path.commands;
            var cl:int = c.length;
            var _cl:int = cl;
            
            n = 360 / len;
            for (var i:int = 0; i <= len; i++ )
            {
                var rad:Number = 0.01745 * (n * i);
                var rad2:Number = 0.01745 * (n * (i+1));
                c[cl++] = 3;
                d[dl++] = Math.cos( rad ) * r + cx;
                d[dl++] = Math.sin( rad ) * r + cy;
                c[cl++] = 3;
                d[dl++] = (Math.cos( rad ) + Math.cos( rad2 )) / 2 * r + cx;
                d[dl++] = (Math.sin( rad ) + Math.sin( rad2 )) / 2 * r + cy;
            }
            c[_cl] = 1; c[_cl+1] = 1;
        }
        public function getPath2(cx:Number, cy:Number, r:Number):GraphicsPath
        {
            var path:GraphicsPath = new GraphicsPath( new <int>[], new <Number>[] );
            appendPath2( path, cx, cy, r );
            return path;
        }
        
    }
}