// The U() macro creates the union of a <0,0,0>,<0,1,0> cylinder // and a subtree at the <0,1,0> end of the cylinder (by making a // recursive T() call). #macro U() union { cylinder { y, 0 I/70 // Radius according to the recursion level pigment { rgb <1 I/6> } // Colored according to the recursion level } #if(I) // Recursively create a subtree and translate it to <0,1,0> T(I-1) translate y } #end rotate // The 'rotate' keyword of the three rotates needed in T() #end // The T() macro creates the union of three subtrees, rotating each one // in different directions. #macro T(I) union { U() <-30,40> } U() -24*z } U() <22,15> } #end // The F() macro creates the "forest", ie. J+1 trees translated randomly. #macro F(J, R) T(6) translate *20 } #if(J) F(J-1 R) #end #end // Instantiate the forest (10 trees): F(9 seed(2)) // Light source: light_source{x,1}