// Last edited on 2003-12-07 13:41:09 by stolfi

#declare ctr = <0,0,0>;
#declare camDir = <00,400,400>;

camera {
  location   ctr + 0.75*camDir
  right      -1.00*x
  up         0.75*y
  sky        y
  look_at    ctr
}

// ======================================================================
// FONTES DE LUZ

light_source {
  10 * < +0.0, +50.0, +50.0 >              // Posição da lâmpada.
  color rgb 1.3 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < +50.0, +50.0, +50.0 >              // Posição da lâmpada.
  color rgb 0.6 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < -50.0, +50.0, +50.0 >             // Posição da lâmpada.
  color rgb 0.4 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

// ======================================================================
// DESCRIÇÃO DA CENA 

background{ color rgb < 0.3, 0.4, 0.5 > }

#macro p1(ang1) 
  union {
    sphere {
      <0,0,0>,2
    }    
    cylinder {
      <0,0,0>,<10,0,0>,1
    }
    sphere {
      <10,0,0>,2
    }    
    rotate ang1
  }
#end

#macro p2(ang2,ang1) 
  union {
    sphere {
      <0,0,0>,2
    }    
    cylinder {
      <0,0,0>,<10,0,0>,1
    }
    object { p1(ang1) translate <10,0,0> }
    rotate ang2
  }  
#end

#macro p3(a3,a2c,a2b,a2a,a1c,a1b,a1a) 
  union {
    sphere {
      <0,0,0>,8
    }
    union {
      object { p2(a2a,a1a) translate<8,0,0>}        
      rotate 30*y
    }
    union {
      object { p2(a2b,a1b) translate<8,0,0>}        
      rotate 30*y
      rotate 120*x
    }
    union {
      object { p2(a2c,a1c) translate<8,0,0>}        
      rotate 30*y
      rotate 240*x
    }
    rotate a3
  }
#end

#macro p4(a4,a3,a2c,a2b,a2a,a1c,a1b,a1a) 
  union {
    object { p3(a3,a2c,a1c,a2b,a1b,a2a,a1a) translate<40,0,0> }
    cylinder { <0,0,0>,<40,0,0>,4 }
    sphere { <0,0,0>,8 }
    rotate a4
  }  
#end

#macro p5(a5,a4,a3,a2c,a2b,a2a,a1c,a1b,a1a) 
  union {
    object { p4(a4,a3,a2c,a1c,a2b,a1b,a2a,a1a) translate<40,0,0> }
    cylinder { <0,0,0>,<40,0,0>,4 }
    sphere { <0,0,0>,8 }
    rotate a5
  }  
#end

#macro cria(i,raiz,raio)
  #local tr=<45,45,45>;
  #local a5=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a4=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a3=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a2a=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a2b=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a2c=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a1a=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a1b=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local a1c=<45,45,45>-90*<rand(raiz),rand(raiz),rand(raiz)>;
  #local cor=<rand(raiz),rand(raiz),rand(raiz)>;
  object { 
    p5(a5,a4,a3,a2c,a2b,a2a,a1c,a1b,a1a) 
    rotate<0,0,-40>
    translate<raio+10,-10,0>
    rotate<0,18*i,0>
    pigment{ color rgb cor }
  }
#end
  
#declare raiz=seed(54325);
#declare i=0;


union { 
  #while(i<20)
    object { cria(i,raiz,50) }
    object { cria(i,raiz,50) rotate <0,9,0> scale<1,-1,1> }
    #declare i=i+1;    
  #end
  #declare cc=<rand(raiz),rand(raiz),rand(raiz)>;
  //cylinder { <0,10,-110>,<0,10,+110>,30 pigment{ color rgb cc }}
  //sphere { <0,10,-110>,30 pigment{ color rgb cc }}
  //sphere { <0,10,+110>,30 pigment{ color rgb cc }}
  torus { 50,15 pigment{ color rgb cc }}
  //rotate <0,90,0>
}