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: Turning Circles(Test)

Get Adobe Flash player
by aobyrne 30 Mar 2011
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/pLkX
 */

// forked from phi16's Turning Circles(Test)
package {
    import flash.display.Graphics;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.text.TextField;
    public class Main extends Sprite {
        public var spr:Sprite=new Sprite();
        private var rad:Number=0;
        private var num:int=24;
        private var invNum:Number;
        private var colors:Array;
        private var radius:Number;
        private var components:Array;
        private var normalizedColors:Array;
        public function Main() {
            spr.x=spr.y=235;
            this.addChild(spr);
            invNum = 1 / num;
            trace( "invNum : " + invNum );
            /*
            this.addEventListener(Event.ENTER_FRAME, this.Draw);
            /*/
            Draw(null);
            //*/
            spr.addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
            spr.addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);
        }
        
        private function mouseOutHandler(e:MouseEvent):void 
        {
            var gr:Graphics = spr.graphics;
            gr.clear();
        }
        
        private function mouseOverHandler(e:MouseEvent):void 
        {
            Sprite(e.currentTarget).name;
            var sprite:Sprite = Sprite(e.target);
            var n:String = sprite.name;
            var gr:Graphics = spr.graphics;
            //*
                var thickness:Number;
                thickness = 3;
                trace( "thickness : " + thickness );
                var r:Number = components[n][0];
                var g:Number = components[n][1];
                var b:Number = components[n][2];
                gr.lineStyle(thickness, 0xff0000,normalizedColors[n][0]);
                gr.moveTo(0, 0);
                gr.lineTo(radius * Math.cos(r), radius * Math.sin(r));
                
                gr.lineStyle(thickness, 0xff00,normalizedColors[n][1]);
                gr.moveTo(0, 0);
                gr.lineTo(radius * Math.cos(g), radius * Math.sin(g));
                
                gr.lineStyle(thickness, 0xff,normalizedColors[n][2]);
                gr.moveTo(0, 0);
                gr.lineTo(radius * Math.cos(b), radius * Math.sin(b));
            //*/
        }
        
        private function sctrace(message:String):void 
        {
            trace( "message : " + message );
        }
        private function Draw(e:Event):void{
            var colorLabel:TextField;
            var radiansPerAngle:Number = Math.PI / 180;
            radius = 160;
            spr.graphics.clear();
            var deltaAngle:Number;
            var color:int;
            var colr:int, colg:int, colb:int;
            var r:Number, g:Number, b:Number;
            var nr:Number, ng:Number, nb:Number;
            var gr:Graphics;
            var sprite:Sprite;
            colors = [];
            components = [];
            normalizedColors = [];
            var normalization:Number = 0.5;
            for(var i:int=0;i<num;i++){
                deltaAngle = i * 360 / num;
                sprite = new Sprite();
                sprite.name = String(i);
                colorLabel = TextField(sprite.addChild(new TextField()));
                colorLabel.text = "";
                colorLabel.scaleX = colorLabel.scaleY = 0.85;
                colorLabel.mouseEnabled = false;
                spr.addChild(sprite);
                r = (deltaAngle + rad) * radiansPerAngle;
                nr = normalization * (Math.sin(r) + 1);
                colr =  nr * 255;
                colorLabel.appendText(colr + ",");
                
                g = (deltaAngle + 120 + rad) * radiansPerAngle;
                ng = normalization * (Math.sin(g) + 1);
                colg =  ng * 255;
                colorLabel.appendText(colg + ",");
                
                b = (deltaAngle - 120 + rad) * radiansPerAngle;
                nb = normalization * (Math.sin(b) + 1);
                colb = nb * 255;
                colorLabel.appendText(colb +"");
                
                components[i] = [r, g, b];
                normalizedColors[i] = [nr, ng, nb];
                color = colr * 256 * 256 + colg * 256 + colb;
                colors[i] = color;
                
                gr = sprite.graphics;
                gr.lineStyle(3, 0);
                gr.beginFill(color);
                var x:Number = Math.cos((deltaAngle + rad) * Math.PI / 180) * radius;
                var y:Number = Math.sin((deltaAngle + rad) * Math.PI / 180) * radius;
                gr.drawCircle(0, 0, 20);
                sprite.y = y;
                sprite.x = x;
                gr.endFill();
                
                
            }
            rad += 2;
            //num = num > 30?12:num +1;
        }
    }
}