Gnarly Tree

Hello there!

Here is a little recursive branching thing I whipped up today, because I had nothing better to do. It is made entirely with actionscript. I was intending it to go in the 25 line AS contest, but I guess Kirupa shut down the submissions today :frowning: I thought today was the last day to *submit. *No big deal though. Please feel free to comment :slight_smile:

function Tree(x, y, direction, splitD, splitN, lw, z) {
 this.Mc = _root.createEmptyMovieClip("wanderer"+(depth++), depth);
 this.Mc.Location = {x:x, y:y};
 this.Mc.Direction = direction;
 this.Mc.splitD = splitD;
 this.Mc.splitN = splitN;
 this.Mc.lw = lw;
 this.Mc.lineStyle(lw, 0, z);
 this.Mc.z = z;
 this.Mc.moveTo(x, y);
 this.Mc.onEnterFrame = function() {
  this.Direction += Math.random()*50-25;
  this.distTraveled += 2;
  if (this.distTraveled>this.splitD) {
   for (var n = 0; n<splitN; n++) Tree(this.Location.x, this.Location.y, this.Direction+Math.random()*40-20, this.splitD*.9, 2, this.lw*.8, this.z*(.6+.4*Math.random()));
   this.onEnterFrame = null;
  } else {
   this.Location.x = this.Location.x+2*Math.cos(this.Direction*Math.PI/180);
   this.Location.y = this.Location.y+2*Math.sin(this.Direction*Math.PI/180);
   this.lineTo(this.Location.x, this.Location.y);
  }
 };
 if (lw<2) this.Mc.removeMovieClip();
}
onMouseDown = function () {
 Tree(_xmouse, _ymouse, -80-Math.random()*20, 30+_ymouse/20, 2, 12, _ymouse/4);
};

Oh btw I reccommend that you not let more than two trees generate at a time. It will get very very laggy, and it might crash your system.