// Animação
// Daniel Kalil Franulovic ra 001525

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

camera {
  location  <  10.00, -50.00, 40.00 >  // Posição do observador.
  right     <-0.60,0.00,0.00>
 // right     -1.0*x                 // Largura RELATIVA da imagem.
 // up        0.75*y                 // Altura RELATIVA da imagem.      
  up        <0.00,0.00,0.80>
  sky       <0.00,0.00,1.00>          // Qual direção é "para cima"?
  look_at   <  13.00, 3.00, 10.00 >  // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

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

#if (mod(clock,0.2)<0.1)
light_source {
  < +10.0, -100.0, +100.0 >             // Posição da lâmpada.
  color rgb 0.5 * < 1.00, 1.00, 0 >   // Intensidade e corda luz.
}
#else
light_source {
  < +10.0, -100.0, +100.0 >             // Posição da lâmpada.
  color rgb 0.7 * < 0, 0, 1.0 >   // Intensidade e corda luz.
}
#end


light_source {
  < +10.0, -70.0, 100.0 >             // Posição da lâmpada.
  color rgb 2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 


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

#declare fonte = seed(4634124659);


#declare prob = 0.7;


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

#declare tinta_preta = 
  texture {
    pigment { color rgb < 0, 0, 0 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.05 ambient 0.1 }
  }


#declare tinta_cinza = 
  texture {
    pigment { color rgb < 0.4, 0.4, 0.4 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.05 ambient 0.1 }
  }

#declare tinta_verde = 
  texture {
    pigment { color rgb < 0, 1, 0 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

 
#declare tinta_marrom = 
  texture {
    pigment { color rgb < 0.3, 0.2, 0.05 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.05 ambient 0.1 }
  }


#declare cor_dourado = <0.9,0.9,0.1>;

#declare dourado = 
  texture {
    pigment {rgb cor_dourado}
    finish {
	ambient 0.05 diffuse 0.05
	reflection cor_dourado
	specular 0.20 roughness 0.05
	}
}


#declare cor_prata = <0.2,0.2,0.2>;

#declare prateado = 
  texture {
    pigment {rgb cor_prata}
    finish {
	ambient 0.05 diffuse 0.05
	reflection cor_prata
	specular 0.20 roughness 0.05
	}
}

#declare cor_cristal = <0.8,0.8,1>;

#declare tx_cristal = 
  texture {
    finish {
	ambient 0.1 diffuse 0.1
	reflection 0.1
	specular 1 roughness 0.001
	}
	pigment {color cor_cristal filter 1}
}


#declare chao = plane { 
	y,50
	texture {tinta_marrom}
}


#declare monitor = 
	box {
	<0,0,0>,
	<3,3,3>
	texture {tinta_cinza}
	}

#declare tela = 
	box {
	<0.3,-0.01,0.3>,
	<2.7,0.02,2.7>
	texture {tinta_preta}
	}


#declare teclado = 

  prism {
    linear_sweep
    linear_spline
    0, // sweep the following shape from here ...
    0.5, // ... up through here
    5, // the number of points making up the shape ...
    <0,0>, <1,1.5>, <4,1.5>, <5,0>, <0, 0>
    texture { tinta_cinza }
    rotate <290,0,0>
  }



#declare computador = 
	object{
	union
		{object {monitor}
		 object {tela}
		 object {teclado translate <-1,-1.5,0>}
		}
	}

#declare coaxial = 
	cylinder {
	<-0.2,0,0>,
	<10.2,0,0>,
	0.2
	texture {prateado}
	}



#declare rede = 
	union {


	//primeiro computador e cabo

	object{computador translate<-13,0,13>}
	object{coaxial translate < -10,1.5,14.5>}


	//pacote vai aki - horizontal

	#if (rand(fonte) < prob)
		
		object{ 
			
			#declare aux = rand(fonte);
		//	#if (aux + clock < 1)

				sphere { <-10 + mod(10*(aux+3.3*clock),10),1.5,14.5>,1 
					pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}	
						
		//	#end

		}
	
	#end		


	//rede


	#declare i = 0;
	#while (i<2)
		#declare j = 0;
		object{computador translate<0,0,0>}
		#while (j<2)
			object{coaxial translate <3 + j*13,1.5,1.5+ i*13>}

		//pacote vai aki - horizontal
			#if (rand(fonte) < prob)
		
			object{ 
				sphere { <3 + j*13 + mod(10*(rand(fonte)+3.3*clock),10),1.5,1.5 + i*13>,1 
						pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}
			}
	
			#end

			#declare j = j + 1;	
			object{computador translate <j*13,0,i*13>}
		#end

		#declare i = i + 1;
		#declare j = 0;
		object{computador translate<j*13,0,i*13>}

		object{coaxial rotate <0,90,0> translate <1.5 + j*13,1.5, i*13>}

		//pacote vai aki - vertical
			#if (rand(fonte) < prob)
		
			object{ 
				sphere { 
						<1.5 + j*13,1.5, (i-1)*13 + mod(10*(rand(fonte)+3.3*clock),10)>,
						1 
						pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}
			}
	
			#end


		#while (j<2)
			object{coaxial translate <3 + j*13,1.5,1.5+ i*13>}

		//pacote vai aki - horizontal
			#if (rand(fonte) < prob)
		
			object{ 
				sphere { 
						<3 + j*13 + mod(10*(rand(fonte)+3.3*clock),10),1.5,1.5 + i*13>,
						1 
						pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}
			}
	
			#end

			#declare j = j + 1;	
			object{computador translate <j*13,0,i*13>}
			object{coaxial rotate <0,90,0> translate <1.5 + j*13,1.5, i*13>}

		//pacote vai aki - vertical
			#if (rand(fonte) < prob)
		
			object{ 
				sphere { 
						<1.5 + j*13,1.5, 13* (i-1) + mod(10*(rand(fonte)+3.3*clock),10)>,
						1 
						pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}
			}
	
			#end


		#end
	#end


	//ultimo computador e cabo

	object{computador translate<39,0,13>}
	object{coaxial translate < 29,1.5,14.5>}

	//pacote vai aki - horizontal

	#if (rand(fonte) < prob)
		
		object{ 
			sphere { <29 + mod(10*(rand(fonte)+3.3*clock),10),1.5,14.5>,1 
					pigment{rgb <rand(fonte),rand(fonte),rand(fonte)>}}
		}
	
	#end


	}



// Aqui está a cena, finalmente:

chao
rede

//computador
//coaxial