frash_ex07_2

by s1190133
♥0 | Line 49 | Modified 2011-07-07 23:02:44 | MIT License
play

ActionScript3 source code

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

package
{
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    
    [SWF(backgroundColor=0x000000, width=465, height=465)]
    public class flash_ex07_2 extends Sprite
    {
        private var ball:Ball;
        private var centerX:int=stage.stageWidth/2;
        private var centerY:int=stage.stageHeight/2;
        private var arr:Array=[];
        
        public function flash_ex07_2()
        {
            stage.scaleMode=StageScaleMode.NO_SCALE;
            stage.align=StageAlign.TOP_LEFT;
            
            for(var i:int=0;i<20;i++){
                ball=new Ball(0xFFFFFF*Math.random());
                ball.x=Math.random()*stage.stageWidth;
                ball.y=Math.random()*stage.stageHeight;
                
                arr[i]=ball;
                addChild(ball);
            }
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
        
        private function onEnterFrame(e:Event):void
        {
            for(var i:int=0;i<20;i++){
                arr[i].x=arr[i].R * Math.cos(Math.PI * arr[i].rad / 180) + centerX;   //回すときの半径R*こさいん(π*回し始めるときの角度rad/360)+中心点
                arr[i].y=arr[i].R * Math.sin(Math.PI * arr[i].rad / 180) + centerY;
                
                arr[i].rad++;               //角度を1増やす
            }
        }
    }
}
import flash.display.Sprite;
class Ball extends Sprite
{
    public var r:Number=Math.random()*20;                 //描く円の半径
    public var R:Number=Math.random()*200;                //回すときの半径
    public var rad:int=Math.random()*360;                 //回し始めるときの角度的な どの角度からはじまんのっていう
    public function Ball(color:Number)
    {
        graphics.beginFill(color);
        graphics.drawCircle(0,0,r);
        graphics.endFill();
    }
}