随机布局

package com.funct
{
    import flash.display.Sprite;

    /**
     *随机布局 
     * @author Administrator
     * 
     */    
    public class Random2 extends Sprite
    {
        public function Random2()
        {
            super();
            init()
        }

        private function init():void
        {
            for (var i:int=0; i < 300; i++)
            {
                var b:Ball=new Ball(1);
                
                var radius:Number=Math.random() * 50;
                //注意这里
                //var radius:Number=Math.sqrt(Math.random()) * 50;
                
                var angle:Number=Math.random() * (Math.PI * 2);

                b.x=stage.stageWidth / 2 + Math.cos(angle) * radius;
                b.y=stage.stageHeight / 2 + Math.sin(angle) * radius;
                
                this.addChild(b);
            }

        }

    }
}
posted @ 2012-04-16 18:30  ndljava  阅读(314)  评论(0编辑  收藏  举报