// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2003-09-04 15:25:26 by stolfi

#include "colors.inc"

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

camera {
  location  <0, 30, -150.00 >  // Posição do observador.
  right     -0.75*x                // Largura RELATIVA da imagem.
  up        1.00*y                 // Altura RELATIVA da imagem.      
 // sky       z                      // Qual direção é "para cima"?
  look_at   <  0.00, 0.00, 0.00 >  // Para onde a câmera está apontando.
 rotate 20*x
 rotate 150*y
 translate<  0.00, 0.00, 0.00 >
} 
// 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

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

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

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

global_settings {
  assumed_gamma 1.0
}

// ----------------------------------------

sky_sphere {
  pigment {
    gradient y
    color_map {
      [0.0 rgb <0.6,0.7,1.0>]
      [0.7 rgb <0.0,0.1,0.8>]
    }
  }
}

#declare azul = 
  texture {
    pigment { color rgb < 0.20, 0.50, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
  
#declare verde = 
  texture {
    pigment { color rgb < 0.00, 1.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare amarelo = 
  texture {
    pigment { color rgb < 1.00, 1.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }  
  
#declare azulclaro = 
  texture {
    pigment { color rgb < 0.00, 1.00, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }
  
  
#declare liga=
cylinder {
	< 5, 10.0, 7 >,
	< 5, 10.0, 15.0 >,
	0.6
	texture { azulclaro }
}	

#declare enfeite = 
union{
   box {
   <-0.2,-1.5,-0.05 >,
   <0.2,1.5, 0.05>   
   pigment { Red }
   }
    //box {
   //<-0.2,8.5,-10.51 >,
   //<0.2,11.5, -10.6>
   //pigment { Red }
  // }
  // box {
  // <-0.2,8.5,-10.01 >,
  // <0.2,11.5, -9.9>
  // pigment { Red }
  // }
}

    
#declare roda =
union{
   cylinder {
	< 0, 10.0, -10.0 >,
	< 0, 10.0, -10.5 >,
	1.7
	pigment { Green }
   }
   object {enfeite   
   rotate 180*clock*z
   translate <0,10,-10.55>}
   object {enfeite   
   rotate 180*clock*z
   translate <0,10,-9.55>}
}	
  
#declare rodas = 
  union {
    #declare i=0;
       #while (i<4)   
       	  #declare r=4.5*i;       
	  //#declare roda =	  
	   //cylinder {
    	//	< r, 10.0, -10.0 >,
    	//	< r, 10.0, -10.5 >,
    	//	1.7
    	//	pigment { Green }
	  // }	  	  
	  object{roda
	  translate <r,0,0>}
	  #declare i = i+1;
	#end	
}


#declare jan=
box{
  <5.5,15,-10.5>,
  <0.5,12,-11>
  texture { azulclaro }
}
#declare gerador = seed(52754);

#declare janelac = 
  union {
    #declare i=0;
       #while (i<5)
          #declare r=3*i;	  
	  #declare aleatorio = rand(gerador);
	  #declare treco =
	  #if (aleatorio<0.5)   
	   cylinder {
    		< r, 10.0, -10.0 >,
    		< r, 10.0, -10.5 >,
    		1.0
    		pigment { Yellow }
	   }	   
	  #else 
	  cylinder {
    		< r, 10.0, -10.0 >,
    		< r, 10.0, -10.5 >,
    		0.5
    		pigment { Red }
	   }	  
	   #end
	  object{treco}
	  #declare i = i+1;
	#end	
}

#declare janelaq = 
  union {
    #declare i=0;
       #while (i<5)
          #declare r=3*i;
	  #declare aleatorio = rand(gerador);
	  #declare treco = 
	  #if (aleatorio<0.5)   
	   box{
  		<r+1.4,15.4,-10>,
  		<r,14,-10.5>
  	   pigment { Green }
	   }
	   #else
	    box{
  		<r+2,16,-10>,
  		<r,14,-10.5>
  	   pigment { Magenta }
	   }		   
	   #end
	  object{treco}
	  #declare i = i+1;
	#end	
}


#declare frente1=
  box {
    < -10.00, 2.0, -10 >,
    < 0.00, 12.00, 0.00 >    
    pigment { Blue }
  }
  
 #declare frente2=
  box {
    < 3.00, 2.0, -10 >,
    < 10.00, 7.00, 0.00 >    
    pigment { Blue }
  }

#declare vagao=
  box {
    < -10.00, 2.0, -10 >,
    < 10.00, 12.00, 0.00 >    
    pigment { Blue }
  }

#declare gerador2 = seed(654321);
#declare aleatorio2 = rand(gerador2);
#declare completo =
   #if (aleatorio2<0.5) 
	union{
	object {vagao}
	object{janelac
	translate<-6.8,0,0>}
	object{janelaq
	translate<-6.8,-5,10.5>}
	object {rodas
	translate<-6.8,-8,0>}
	object {rodas
	translate<-6.8,-8,10.5>}
	object {vagao}
	object{liga
	translate<-10,-4,3>
	rotate -90*y}
   #else
        union{
	object {vagao}
	object{janelaq
	translate<-6.8,-5,0>}
	object{janelac
	translate<-6.8,0,10.5>}
	object {rodas
	translate<-6.8,-8,0>}
	object {rodas
	translate<-6.8,-8,10.5>}
	object {vagao}
	object{liga
	translate<-10,-4,3>
	rotate -90*y}
    #end
}

#declare trilhoext=  
cylinder {
	< 0, 0, 0 >,
	< 0, 0.5, 0 >,
	55
	texture { amarelo }
}

#declare trilhoextaux=  
cylinder {
	< 0, -0.1, 0 >,
	< 0, 0.6, 0 >,
	54
	texture { azulclaro }
}	  

#declare trilhoint=  
cylinder {
	< 0, 0.0, 0 >,
	< 0, 0.5, 0 >,
	45
	texture { amarelo }
}

#declare trilhointaux=  
cylinder {
	< 0, -0.1, 0 >,
	< 0, 0.6, 0 >,
	44
	texture { azulclaro }
}

#declare frente=
union{
object{frente1
translate<-13,0,0>}  
object{frente2
translate<-33,0,0>}  
object {rodas
translate<-28,-8,0>}
object {rodas
translate<-28,-8,10.5>}
object {jan
translate<-21,-4,0>}
object {jan
translate<-21,-4,10.6>}    
}   


#declare trem = 
  union {
	#declare cont = 0;
	#while(cont<5)
	  #declare r = 30*cont; 
	  object{completo
	   translate<0,0,-45>
	   rotate r*y  
	  }       
	  #declare cont = cont + 1;
	#end
	object {frente
	 translate<20,0,-45>
	 rotate 145*y
	}       
}

#declare tempo=clock;
#declare h=0.2;
#declare D=360;
#declare A=D/(2*h*(1-h));
#declare B=-A*h*h;
#declare C=2*A*h;


// ----------------------------------------

plane {
  y, -1
  pigment { color rgb <0.7,0.5,0.3> }
}

union{
difference{ 
  object {trilhoext} 
  object {trilhoextaux} 
}
difference{ 
object {trilhoint} 
object {trilhointaux} 
}
}
 #if (tempo<0.2)
    object {trem rotate A*clock*clock*y}
 #else 
    #if (tempo<0.8)
       object {trem rotate (B+C*clock)*y}
    #else object {trem rotate (D-A*(1-clock)*(1-clock))*y}
    #end
 #end