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