布朗运动

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

    /**
     * 布朗运动 
     * @author Administrator
     * 
     */    
    public class Brownian1 extends Sprite
    {
        private var balls:Array=[];
        private var fir:Number=.95;
        private var num:Number=50;

        public function Brownian1()
        {
            super();
            init();
        }

        private function init():void
        {
            for (var i:int=0; i < num; i++)
            {
                var b:Ball=new Ball(1);
                b.x=Math.random() * stage.stageWidth;
                b.y=Math.random() * stage.stageHeight;

                b.vx=0;
                b.vy=0;

                this.addChild(b);

                balls.push(b);
            }

            this.addEventListener(Event.ENTER_FRAME, onEnterFrame)
            graphics.lineStyle(0, 0, 5);
        }

        /**
         * 布朗运动画线 ---带状
         * @param e
         * 
         */        
        private function onEnterFrame(e:Event):void
        {
            //graphics.clear()
            for (var i:int=0; i < num; i++)
            {
                var b:Ball=balls[i];
                graphics.moveTo(b.x, b.y);

                b.vx+=Math.random() * .2 - .1;
                b.vy+=Math.random() * .2 - .1;

                b.x+=b.vx;
                b.y+=b.vy;

                b.vy*=fir;
                b.vx*=fir;

                graphics.lineTo(b.x, b.y);
            }


        }

//        private function onEnterFrame(e:Event):void
//        {
//            for (var i:int=0; i < num; i++)
//            {
//                var b:Ball=balls[i];
//                b.vx+=Math.random() * .2 - .1;
//                b.vy+=Math.random() * .2 - .1;
//                
//                b.x+=b.vx;
//                b.y+=b.vy;
//                
//                b.vy*=fir;
//                b.vx*=fir;
//                
//                
//                if (b.x > stage.stageWidth)
//                {
//                    b.x=0;
//                }
//                else if (b.x < 0)
//                {
//                    b.x=stage.stageWidth;
//                }
//                
//                if (b.y > stage.stageHeight)
//                {
//                    b.y=0;
//                }
//                else if (b.y < 0)
//                {
//                    b.y=stage.stageHeight;
//                }
//                
//            }
//            
//            
//        }

    }
}

转载于:https://www.cnblogs.com/ndljava/archive/2012/04/16/2451784.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值