#include "colors.inc"
#include "textures.inc"

// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2003-07-31 12:50:37 by stolfi

// ======================================================================
// CÂMERA 

camera {
    sky z
    location < -5.00, -2.00, 25.00 > // Posição do observador.
    look_at < 10.00, 10.00, 5.00 >     // Para onde a câmera está apontando.
} 



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

light_source {
    10 * < 10.00, 12.00, 15.00 >               // Posição da lâmpada.
    color rgb < 1.00, 1.00, 1.00 > // Intensidade e cor da luz.
} 

light_source {
    < 50.00, 40.00, 25.00 >               // Posição da lâmpada.
    color rgb < 1.00, 1.00, 1.00 > // Intensidade e cor da luz.
} 

light_source {
    < 12.00, -12.00, 5.00 >                 // Posição da lâmpada.
    color rgb < 1.00, 1.00, 1.00 > // Intensidade e cor da luz.
} 

light_source {
    < 10.00, 5.00, 15.00 >                 // Posição da lâmpada.
    color rgb < 1.00, 1.00, 1.00 > // Intensidade e cor da luz.
} 

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

background { color rgb < 0.68, 1.00, 0.65 > }

#declare plano_xy =
    plane {
        < 0, 0, 1 >,
        0
    }

#declare Semente = seed ( 12345 );

#declare EsferaT =
   texture { 
      Polished_Chrome 
      pigment { color rgb <1, 0.8, 0.2> * 0.8 }
      finish { ambient 0.2 diffuse 0.75 phong 1 }
   }

#declare CilindroT = 
   texture {
      Polished_Chrome 
      pigment { color rgb <0.8, 0.7, 0.6> }
      finish { ambient 0.2 diffuse 0.75 phong 1 }
   }

#declare rede = 
   union {
      #declare TAM = 5;

      #declare Y = 1; 
      #while( Y <= TAM )

         #declare X = TAM - Y + 1; 
         #while( X <= TAM + Y - 1 ) 

            union {
               sphere {
                  < 0, 0, 0 >, 0.5 
                  texture { EsferaT }
                  pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
               } 

               #if ( Y < TAM )
                  cylinder {
                     < 0, 0, 0 >, < 0, 3, 0>, 0.1 
                     texture { CilindroT }
                     pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                  }

                  #if ( X = TAM - Y + 1 )
                     cylinder {
                        < 0, 0, 0 >, < -3, 3, 0>, 0.1
                        texture { CilindroT }
                        pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                     }

                  #end

                  #if ( X = TAM + Y - 1 )
                     cylinder {
                        < 0, 0, 0 >, < 3, 3, 0>, 0.1
                        texture { CilindroT }
                        pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                     }
                  #end

                  #if ( rand(Semente) < 0.6 ) 
                     box {
                        < 0.20, 0.20, 0.20>,
                        < -0.20, -0.20, -0.20>
                        pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                        translate < 0, 3 * rand(Semente), 0>
                     }  
                  #end

               #end

               #if (  X < TAM + Y - 1 )
                  cylinder {
                     < 0, 0, 0 >, < 3, 0, 0>, 0.1
                     texture { CilindroT }
                     pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                  }

                  #if ( rand(Semente) < 0.4 ) 
                     box {
                        < 0.20, 0.20, 0.20>,
                        < -0.20, -0.20, -0.20>
                        pigment { color rgb <rand(Semente), rand(Semente), rand(Semente)> }
                        translate < 3 * rand(Semente), 0, 0>
                     }  
                  #end

               #end


               translate < 3 * X, 3 * Y, 4>
            }

            #declare X = X + 1;
         #end

         #declare Y = Y + 1;
      #end 
   }


// Aqui está a cena, finalmente:
union {
    object {
        plano_xy
	pigment {
            checker rgb < 0.00, 0.00, 0.30 >, < 0.00, 0.00, 0.50 >
        }
    }

    object { rede }
}