Tag Archives: random walk

Random Walk

Actionscript:
  1. var xp:Number=Math.random() * stage.stageWidth;
  2. var yp:Number=Math.random() * stage.stageHeight;
  3. graphics.lineStyle(0,0x000000);
  4. graphics.moveTo(xp, yp);
  5. addEventListener(Event.ENTER_FRAME, onLoop);
  6. function onLoop(evt:Event):void {
  7.     xp+=Math.random()*10-5;
  8.     yp+=Math.random()*10-5;
  9.     graphics.lineTo(xp, yp);
  10. }

Nothing special here, but its good to know that this technique has a name... and that it's NOT Brownian Motion... more here.

Posted in Graphics, motion | Also tagged , | Leave a comment