POV-Ray : Newsgroups : povray.general : I am having a lot of problems writting a recursive function : I am having a lot of problems writting a recursive function Server Time
2 Aug 2024 20:16:01 EDT (-0400)
  I am having a lot of problems writting a recursive function  
From: Jay D  Patteson
Date: 24 Aug 2004 21:40:00
Message: <web.412bed2c6402a89bb46190930@news.povray.org>
I have been working on a fractal tree.  I know that there is probably tons
and tons of source code to pick from, but I wanted to figure it out myself.
 I have "successfully done it"  But I couldn't figure out the recursive
fuctions.

I wound up having to have a macro call the second macro which called the
third, etc until 16 or so.  So I wrote 16 macros, when I bet I could have
done it with a simple recursive macro.  :(

Could anyone help me figure out how to change this:

#version 3.5;
#include "colors.inc"
#include "math.inc"

#declare R1 = seed(0);

global_settings {
  assumed_gamma 1.0
}

camera {
  location  <-40.0, 10, -0.0>

  look_at   <0.0, 10,  0.0>
}
sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}
light_source {
  <-50, 100, -100>
  color rgb <1, 1, 1>

}



#macro leave(aty,rotz, scl)

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>

}
#end

#macro tree(aty,rotz, scl)
union {
cylinder { <0, 0, 0>, <0, 8, 0>, 1 }
sphere {<0,8,0>,1.2}

texture {
  pigment {
    wood
    color_map {
      [0.1 color red .5]
      [0.5 color red .2]
    }
    turbulence 0.5
    scale <1,3,1>
  }
  normal {
    wood 0.3
    turbulence 0.5
    scale <1,3,1>
  }
  finish {

    specular 0.6
  }
}


scale <scl,scl,scl>
rotate <0,0,rotz>
translate <0,aty,0>

}
#end

#macro tree2(aty,rotz, scl)
union {
tree(0,0,1)
leave(8,atan2d(4,3),.75)
leave(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree3(aty,rotz, scl)
union {
tree(0,0,1)
tree2(8,atan2d(4,3),.75)
tree2(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree4(aty,rotz, scl)
union {
tree(0,0,1)
tree3(8,atan2d(4,3),.75)
tree3(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree5(aty,rotz, scl)
union {
tree(0,0,1)
tree4(8,atan2d(4,3),.75)
tree4(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree6(aty,rotz, scl)
union {
tree(0,0,1)
tree5(8,atan2d(4,3),.75)
tree5(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree7(aty,rotz, scl)
union {
tree(0,0,1)
tree6(8,atan2d(4,3),.75)
tree6(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end

#macro tree8(aty,rotz, scl)
union {
tree(0,0,1)
tree7(8,atan2d(4,3),.75)
tree7(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree9(aty,rotz, scl)
union {
tree(0,0,1)
tree8(8,atan2d(4,3),.75)
tree8(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree10(aty,rotz, scl)
union {
tree(0,0,1)
tree9(8,atan2d(4,3),.75)
tree9(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree11(aty,rotz, scl)
union {
tree(0,0,1)
tree10(8,atan2d(4,3),.75)
tree10(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree12(aty,rotz, scl)
union {
tree(0,0,1)
tree11(8,atan2d(4,3),.75)
tree11(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree13(aty,rotz, scl)
union {
tree(0,0,1)
tree12(8,atan2d(4,3),.75)
tree12(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree14(aty,rotz, scl)
union {
tree(0,0,1)
tree13(8,atan2d(4,3),.75)
tree13(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree15(aty,rotz, scl)
union {
tree(0,0,1)
tree14(8,atan2d(4,3),.75)
tree14(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end
#macro tree16(aty,rotz, scl)
union {
tree(0,0,1)
tree15(8,atan2d(4,3),.75)
tree15(7,-atan2d(3,4),.75)
scale <scl,scl,scl>
rotate <0,72,rotz>
translate <0,aty,0>
}
#end



// call the tree here!

tree16(0,0,1)





plane {
  y, 0
texture
{
  pigment
  {
    dents
    color_map {[0.1 color green .7] [0.5 color green .5]}
    turbulence 0.5
    scale <5,1,5>
  }

  normal
  {
    marble
    turbulence 1
    scale <1,1,1>
  }
}
}


Post a reply to this message

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