recursion help please!

hi guys,

so im working on a program that recursively draws trees, and im kinda stuck on my algorithm

basically my main draws the tree trunk

then i have a function that uses some input length n and a radian angle theta and draws polar lines. each time the n decreases and so does theta to give the tree a natural bending look.

any idea how to implement this so that i can draw two lines from ever finished line using recursion?

Are you trying to draw a fractal tree of lines?

Then it's just
1
2
3
4
5
6
7
void line( point start, length n, angle theta ){
   if (n==0) return;
   point end = start + makevector(theta)*length;
   drawline (start, end);
   line (end, n-1, theta+delta);
   line (end, n-1, theta-delta);
}
Note that you have to pass the beginning of each line too.
its a stylized line tree so it would look similar to this:

http://www.lemlinh.com/wp-content/uploads/2008/08/8-30-2008-3-11-28-am-thumb.jpg

thank you for your help though !

i have somthing similar to your code, it is difficult for me to understand how to start again at every single end point since there is so many !
Topic archived. No new replies allowed.