Actionscript:
-
var branches:int = 0;
-
var maxBranches:int = 400;
-
-
graphics.lineStyle(0,0x000000);
-
-
makeBranch(300,350,100,-45,45);
-
-
function makeBranch(xp:Number, yp:Number, leng:Number, min:Number, max:Number):void {
-
-
var endX:Number, endY:Number;
-
var theta:Number = (min + Math.random()*(max-min) - 90) * Math.PI / 180;
-
-
endX = xp + leng * Math.cos(theta);
-
endY = yp + leng * Math.sin(theta);
-
-
graphics.moveTo(xp, yp);
-
graphics.lineTo(endX, endY);
-
-
if (branches <maxBranches) {
-
var newLength:Number = leng*.7;
-
setTimeout(makeBranch, 0, endX, endY, newLength, -90, 0);
-
setTimeout(makeBranch, 0, endX, endY, newLength, 0, 90);
-
}
-
branches+=2;
-
}
Draws a tree using recursion.