// Last edited on DATE TIME by USER
// Processed by remove-cam-lights








#declare randvar = seed(032883);


#declare raio_minimo = 0.1;
#declare fator_diminui_L = 0.22;
#declare fator_diminui_r = 0.07;
#declare fruto = 0.3;


#declare b1 = <0,0,0>;
#declare b2 = <50, 50, 50>;

  






 




background{ color rgb < 0.75, 0.80, 0.85 > }




#declare ouro =
  texture {
   pigment { color rgb < 0.90, 0.80, 0.00 > }
   finish {
    ambient 0.2
    diffuse 0.3
    specular 0.3 roughness 0.005
    reflection 0.2
   }    
  }
  
#declare rubi =
  texture {
   pigment { color rgb < 0.90, 0.00, 0.00 > filter 1.0 }
   finish {
    ambient 0.2
    diffuse 0.3
    specular 0.3 roughness 0.005
    reflection 0.2
   }
  }
  
#declare marrom_claro = 
  texture {
    pigment { color rgb < 1.00, 0.95, 0.90 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
  
#declare marrom_escuro = 
  texture {
    pigment { color rgb < 0.50, 0.40, 0.40 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }


#macro desenha_galho(base, cap, r)
 cylinder 
 {
  base, cap, r
  texture { marrom_claro }
 }

#end

#macro desenha_fruto(centro)
 union {
  sphere
  {
   centro, fruto
   texture { rubi }
  }
  sphere
  {
   centro, fruto
   translate <-fruto,0,-2 * fruto>
   texture { rubi }
  }
  sphere
  {
   centro, fruto
   translate <+fruto,0,-2 * fruto>
   texture { rubi }
  }
  sphere
  {
   centro, fruto
   translate <0,-fruto,-2 * fruto>
   texture { rubi }
  }
  sphere
  {
   centro, fruto
   translate <0,+fruto,-2 * fruto>
   texture { rubi }
  }
  sphere
  {
   centro, fruto
   translate <0,0,-4 * fruto>
   texture { rubi }
  }

 }
#end

#macro galho(base,dir,L,r)

 
 #local dest = base + (dir * L); 

 #if ((r < raio_minimo) | 
  (dest.x < b1.x) | (dest.x > b2.x ) |
  (dest.y < b1.y) | (dest.y > b2.y ) |
  (dest.z < b1.z) | (dest.z > b2.z ))
  desenha_fruto(base)
 #else
  desenha_galho(base, dest, r)

  #local r1 = <0.5 - rand(randvar), 0.5 - rand(randvar), 0.5 - rand(randvar)>;
  #local r2 = <0.5 - rand(randvar), 0.5 - rand(randvar), 0.5 - rand(randvar)>;

  #local novo_dir1 = vnormalize(dir + r1);
  #local novo_dir2 = vnormalize(dir + r2);

  #local novo_L = L - fator_diminui_L;
  #local novo_r = r - fator_diminui_r;
  
  union {
   galho(dest, novo_dir1, novo_L, novo_r)
   galho(dest, novo_dir2, novo_L, novo_r)
  }
  

 #end

#end




plane {
        z, 0
 texture
        {
                pigment { checker color rgb < 0.7, 0.8, 0.7 >, color rgb < 0.9, 
0.9, 1.0 > }
        }
}

galho(<(b1.x + b2.x) / 2, (b1.y + b2.y) / 2,0>,<0,0,1>, 6.5, 0.6)


// Original camera parameters:
// #local cam_ctr = <0.00,20.0,20.00>
// #local cam_vec = (<-60.00,0.00,20.00>-<0.00,20.0,20.00>)
// #local cam_sky = z

#include "camlight.inc"
camlight(<0.00,20.0,20.00>,<10,10,10>,20.0,z,1.0)