In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

RandomWalk

By Danny Miller
*	www.K2xL.com; K2xL@K2xL.com
*	Let me know if you are learning from this code! 
*   I would love to hear if/how I'm helping people out with their Flash learning or projects.
Get Adobe Flash player
by k2xl 01 Apr 2009
/**
*	By Danny Miller
*	www.K2xL.com; K2xL@K2xL.com
*	Let me know if you are learning from this code! 
*   I would love to hear if/how I'm helping people out with their Flash learning or projects.
*/
package {
	import flash.display.*;
	import flash.events.*;
	public class RandomWalk extends MovieClip {
		private var Sh:Shape = new Shape();
		private var BD:BitmapData=new BitmapData(512,512,false,0);
		private var b:Bitmap=new Bitmap(BD);
		public function RandomWalk() {
			stage.addEventListener(MouseEvent.CLICK,drawIt);

			drawIt();
			addChild(b);
			addChild(Sh);
		}
		private function drawIt(e:Event=null):void {
			Sh.graphics.clear();
			Sh.graphics.lineStyle(1,0xFFFFFF);
			var X:Number=512/2;
			var Y:Number=512/2;
			Sh.graphics.moveTo(X,Y);
			BD.fillRect(BD.rect,0);
			BD.lock();
			for (var i:int = 0; i < 7680; i++) {
				var r:Number=Math.random();
				if (r<=1/8) {
					Y+=3;
				} else if (r <= 2/8) {
					X+=3;
				} else if (r <= 3/8) {
					X+=3;
					Y+=3;
				} else if (r <= 4/8) {
					X+=-3;
					Y+=-3;
				} else if (r <= 5/8) {
					Y+=-3;
				} else if (r <= 6/8) {
					X+=-3;
				} else if (r <= 7/8) {
					Y+=3;
					X+=-3;
				} else if (r <= 1) {
					Y+=-3;
					X+=3;
				}
				Sh.graphics.lineTo(X,Y);
				BD.setPixel(X,Y,0xFFFFF);
			}
			BD.unlock();
		}
	}
}