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

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

#declare raio = 2.000;

#declare cor_Amarela = <1, 0.8, 0.1>;

#declare tinta_Azul =
  texture {
    pigment { color rgb < 0.00, 0.00, 1.00 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta_Preta =
  texture {
    pigment { color rgb < 0.00, 0.00, 0.00 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta_Verde =
  texture {
    pigment { color rgb < 0.00, 1.00, 1.00 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta_Vermelha =
  texture {
    pigment { color rgb < 1.00, 0.00, 0.00 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta1 =
  texture {
    pigment { color rgb < 0.30, 0.50, 0.20 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare tinta_X =
  texture {
    pigment { color rgb < 0.75, 0.8, 0.85 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.1 }
  }

#declare roda =
  cylinder {
    < 0, -1, 0 >,
    < 0, -1.1,0>,
    0.5
    texture { tinta_X }
  }

#declare janela_redonda =
  cylinder {
    < 1, -1.05, 1.5 >,
    < 1, 1.05, 1.5 >,
    0.2
    texture { tinta_Vermelha }
  }

#declare janela_quadrada =
  box {
    <0.8,-1.05,1.70>,
    <1.2,1.05,1.30>
    texture { tinta_Azul }
  }

#declare maquina =
  union{
    box {
      <-0.5,-1.00,0>,
      <3.5,1.00,0.1>
      texture { tinta1 }
    }
    box {
      <-0.5,-1.00,0.1>,
      <1.25,1.00,2>
      texture { tinta1 }
    }
    difference{
      cylinder {
        < 1.25, 0, 0.1 >,
        < 3.5, 0, 0.1>,
        1
        texture { tinta_Azul }
      }
      box {
        <-0.6,-1.10,-1.5>,
        <3.6,1.10,0>
        texture { tinta_Azul }
      }
    }
    cylinder {
      < 2.8, 0, 0.1 >,
      < 2.8, 0, 2.5>,
      0.3
      texture { tinta_Azul }
    }
  #declare j=0;
  #while (j<4)
    object{roda translate<j,0,0>}
    object{roda translate<j,2.1,0>}
    #declare j=j+1;
  #end

  #declare i=0;

  #while (i<3)
    object{janela_quadrada translate<-0.5*i,0,0>}
    #declare i=i+1;
  #end
  }

#declare vagao =
  union{
  box {
    <-5.5,-1.00,0>,
    <-1.5,1.00,2>
    texture { tinta_Verde }
  }
  #declare q=0;
  #while (q<4)
    object{roda translate<-5+q,0,0>}
    object{roda translate<-5+q,2.1,0>}
    #declare q=q+1;
  #end
  }

#declare trilho =
  union{
    torus {20.5,0.1  texture { tinta_Preta } rotate 90*x translate<0,0,-0.7>}
    torus {18.5,0.1  texture { tinta_Preta } rotate 90*x translate<0,0,-0.7>}
  }

plane { z,-0.7
  texture{
    pigment { color rgb < 0.60, 0.30, 0.10 > }
    finish { ambient 0.1 diffuse 0.9 }
    scale 5
  }
}

#declare gerador = seed(99999);

#declare cada_vagao=
  union{
    object{vagao}
    #declare w=0;
    #while (w<3)
      #if (rand(gerador)>=0.5)
        object{ janela_redonda translate<-5.5+w,0,0>}
      #else
        object{ janela_quadrada translate<-5.5+w,0,0>}
      #end
      #declare w=w+1;
    #end
  }

#declare trem =
  union{
    object{maquina rotate -90*z translate<19.5,0,0> }

    #declare k=0;
    #while (k<6)
      object{cada_vagao rotate -80*z translate<19.5,0,0> rotate 15*k*z }
      #declare k=k+1;
    #end
  }

#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;

#if (tempo<0.2)
  #declare posicao = -(A*clock*clock);
#else
  #if (tempo<0.8)
    #declare posicao = -(B+C*clock);
  #else  #declare posicao = -(D-A*(1-clock)*(1-clock));
  #end
#end

union{
  object{ trilho }

  box{
  <23,-5, -1>
  <26,5,5>
  rotate 100*z
  }

  object{ trem rotate 100*z rotate posicao*z }
}

#include "camlight.inc"
camlight(<0,0,0>,<60.00,39.00,24.00>,1.00,z,1.0)