POV-Ray : Newsgroups : povray.general : I am having a lot of problems writting a recursive function : Re: I am having a lot of problems writting a recursive function Server Time
2 Aug 2024 20:21:11 EDT (-0400)
  Re: I am having a lot of problems writting a recursive function  
From: Nicolas Alvarez
Date: 1 Sep 2004 20:06:14
Message: <413663f6@news.povray.org>

news:412bf930$1@news.povray.org...
>
> #macro buildtree(aty,rotz, scl,  depth)
>  union {
>  tree(0,0,1)
>  #if (depth = 15)
>   leave(8,atan2d(4,3),.75)
>   leave(7,-atan2d(3,4),.75)
>  #else
>   buildtree(8,atan2d(4,3),.75, depth+1) // depth increases with each call
>   buildtree(7,-atan2d(3,4),.75, depth+1)
>  #end
>  scale <scl,scl,scl>
>  rotate <0,72,rotz>
>  translate <0,aty,0>
> }
>
> buildtree(0,0,1, 0 /* initial depth of zero */)
>

There is a better way to do it:

 #macro buildtree(aty,rotz, scl,  depth)
  union {
  tree(0,0,1)
  #if (depth = 16)
   cylinder { <0, 0, 0>, <0, 10, 0>, 1
    pigment{ rgb <0,1,0>}

    scale <scl*4,scl*2,scl/3>
    rotate <0,0,rotz>
    translate <0,aty,0>
   }
  #else
   buildtree(8,atan2d(4,3),.75, depth+1) // depth increases with each call
   buildtree(7,-atan2d(3,4),.75, depth+1)
  #end
  scale <scl,scl,scl>
  rotate <0,72,rotz>
  translate <0,aty,0>
 }

--
- Nicolas Alvarez
nicoalvar0 [at] hotmail [dot] com


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.