// Last edited on 2005-01-06 00:21:08 by stolfi
// Processed by remove-cam-lights

background{ color rgb < 0.75, 0.80, 0.85 > }
#declare cor_dourada = < 0.80, 0.80, 0.05 >;
#declare tinta_dourada =
  texture {
    pigment { rgb cor_dourada }
    finish { diffuse 0.05 specular 0.20 roughness 0.05
             ambient 0.05 reflection cor_dourada }
  }

#declare cor_folha =
  texture {
    pigment { color rgb < 0.15, 0.75, 0.15 > }
    finish { diffuse 0.4 roughness 0.3 }
  }

#declare cor_tronco =
  texture {
    pigment { color rgb < 0.35, 0.35, 0.15 > }
    finish { diffuse 0.4 roughness 0.3 }
  }

#declare chao =
  plane {
    y,
    0
    texture {
      pigment { checker <0.10, 0.10, 0.25>, <0.30, 0.30, 0.30> }
      finish {diffuse 0.3}
      scale 8
    }
  }

#declare G = seed(25745);
#declare angEntreRamos=35;
#declare limiar = 0.04;

#macro arvore(nivel)
  #if (nivel > 0)
    union {
      #local altura = nivel*4 + 1.5;
      #local raio = nivel * 0.3;
      cylinder {<0,0,0>, <0,altura,0>, raio texture {cor_tronco}}
      #if (nivel > 1)
        sphere {<0,altura,0>, raio * 1.2 texture {cor_tronco}}
        #local sub = arvore(nivel-1)
        #local possiveis = 5 * (1 - rand(G)*rand(G));
        #local angRot = 360/possiveis;
        #local i=0;
        #while (i < possiveis)
          #if (rand(G) >= limiar)
            object { sub
              rotate <angEntreRamos + 5*(0.5-rand(G)), 5*(0.5-rand(G)) + angRot*i,0>
              translate <0,altura,0> }
          #end
          #local i=i+1;
        #end
      #else
        cylinder {<0,altura,0.2>, <0,altura,-0.2>, raio*2 texture {cor_folha}}
      #end
    }
  #end
#end

union {
  arvore(7)
  object { chao }
}

#include "camlight.inc"
camlight(<0,55,0>,<130,95,130>,1.00,y,1.0)