flash on 2010-2-10

by _ex_
♥0 | Line 53 | Modified 2010-02-10 14:01:06 | MIT License
play

ActionScript3 source code

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

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
                width="450" height="450" backgroundColor="#FFFFFF" xmlns="*">

    <mx:ApplicationControlBar dock="true" width="100%">
        <mx:Label x="10" y="10" text="Circles:"/>
        <mx:NumericStepper id="cntNumber" value="13" minimum="1" maximum="100"
                           change="canvas.n = cntNumber.value; canvas.draw();"/>
        <mx:Label x="10" y="10" text="Big Radius:"/>
        <mx:NumericStepper id="cntRadiusBig" value="180" minimum="10" maximum="400" stepSize="10"
                           change="canvas.R = cntRadiusBig.value; canvas.draw();"/>
        <mx:Label x="10" y="10" text="Small Radius:"/>
        <mx:NumericStepper id="cntRadiusSmall" value="85" minimum="10" maximum="400" stepSize="5"
                           change="canvas.r = cntRadiusSmall.value; canvas.draw();"/>
    </mx:ApplicationControlBar>

    <mx:Canvas width="100%" height="100%" x="0" y="0" backgroundColor="#FFFFFF">
        <DemoCanvas id="canvas"/>
    </mx:Canvas>

    <mx:Component className="DemoCanvas">
        <mx:UIComponent creationComplete="draw()">
            <mx:Script>
                <![CDATA[

        public var n:int = 15;
        public var R:int = 180;
        public var r:int = 85;

        public function draw():void {
            this.graphics.clear();
            drawCircles(this.parent.width / 2, this.parent.height / 2);
        }

        public function drawCircles(ox:int, oy:int):void {
            drawCircle(ox, oy, R, 0x999999, 0, 0);
            var inc:Number = (2 * Math.PI) / n;
            for (var k:int = 0; k < n; ++k) {
                var cx:Number = ox + (R - r) * Math.sin(k * inc);
                var cy:Number = oy + (R - r) * Math.cos(k * inc);
                drawCircle(cx, cy, r, 0xFF0000, 0, 0);
            }
        }

        public function drawCircle(x:int, y:int,
                                   radius:int,
                                   borderColor:Number = 0x000000,
                                   colorBody:Number = 0xFFFFFF,
                                   alpha:Number = 1.0,
                                   borderSize:Number = 0.5):void {

            this.graphics.lineStyle(borderSize, borderColor);
            this.graphics.beginFill(colorBody, alpha);
            this.graphics.drawCircle(x, y, radius);
            this.graphics.endFill();
        }
                ]]>
            </mx:Script>
        </mx:UIComponent>
    </mx:Component>
</mx:Application>