Say I have a recursive algorithm, for example one that generates a random tree:
// Pseudocode, just a simple algorithm: it isn't perfect.
function generate_branch(angle, length, current_depth, max_depth) {
var branch = Branch(angle, length); // creates a new branch
if (current_depth == max_depth) {
return branch;
}
current_depth++;
// random_int(min, max)
branch.subbranches[] = generate_branch(random_int(0, angle + random_int(-30, 30)),
random_int(0, 20)
current_depth,
max_depth);
// ^^^^ recursion
return branch;
}
var trunk = generate_branch(0, random_int(10), 0, 5);
RenderTree(trunk);
The problem is that this will render the entire tree in one frame. If I want to animate this (i.e. grow the tree over time), how would I do that? What is the best way to do this?
The game uses a game loop.