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

background{ color rgb < 0.15, 0.40, 0.95 > }

#declare tx_verde =
  texture{
    pigment{ color rgb < 0.10, 0.90, 0.10 > }
  }

#declare tx_azul =
  texture{
    pigment{ color rgb < 0.15, 0.30, 1.00 > }
  }

#declare tx_bege =
  texture{
    pigment{ color rgb < 0.85, 0.90, 0.30 > }
  }

#declare tx_marrom =
  texture{
    pigment{ color rgb < 0.85, 0.60, 0.30 > }
  }

#declare tx_4 =
  texture{
    pigment{ color rgb < 0.15, 0.60, 0.80 > }
  }

#declare tx_pele =
  texture{
    pigment{ color rgb < 0.85, 0.80, 0.10 > }
  }

#declare chao =
  box{ <-50,-50,-10>, <+20,+20,0> }

#declare campo =
  box {<0,0,0>, <3,2,0>}

#declare roleta = seed (315);

#macro escada(n)
  union {
    #declare i = 0;
    #while (i < n)
        box {<0,i+1,i>, <1,i,i> }
        box {<1,i+1,i+1>, <0,i+1,i>}
        #declare i = i + 1;
    #end
  }
#end

#macro torcedor(tx /*textura*/)
  union {
    sphere { <0,0,3>, 0.5 texture { tx_pele }}
    cylinder { <0,0,2.5>, <0,0,1.0>, 0.5 texture { tx } } // corpo
    cylinder { <0.3,0,1>, <0.3,0,0.25>, 0.1 texture { tx_pele } }
    cylinder { <-0.3,0,1>, <-0.3,0,0.25>, 0.1 texture { tx_pele } }
    cylinder { <0.5,0.0,2.0>, <1.0,0.0,2.0>, 0.1 texture { tx_pele } }
    cylinder { <-0.5,0.0,2.0>, <-1.0,0.0,2.0>, 0.1 texture { tx_pele } }
    scale(0.4)
    translate <0.5, 0.3, 0>
  }
#end

#macro deslocamento(tt /*clock*/, t0, t1 /* tempo inicial e final da ola daquela seção*/)
        #if ((tt >= t0) & (tt <= t1))
                #local desloc = sin(((tt - t0) / (t1 - t0)) * pi);
        #end

        #if ((tt < t0) | (tt > t1))
                #local desloc = 0;
        #end

        desloc
#end

#macro secao (m /*fileiras*/, n /*assentos por fileiras*/, tt /*clock*/, t0, t1 /* tempo inicial e final da ola daquela seção*/)
  union {
    #declare i = 0;
    #while (i < m)
        box {<0,i+1,i>, <n,i,i> } // base
        box {<n,i+1,i+1>, <0,i+1,i>} // encosto
        #declare j = 0;
        #while (j < n)
          box {<j+0.1,i+0.9,i>, <j+0.9,i,i+0.1> texture {tx_4} } // acento

          #if (rand(roleta) < 0.90)

          object {torcedor(
            #if (rand(roleta) < 0.25)
              tx_azul
            #else
              tx_verde
            #end
          )

          #local periodo = (t1 - t0) / n;

          #local inicio_movimento = t0 + periodo * (j-2);
          #local final_movimento = inicio_movimento + periodo*5;

          translate <j,i,i + deslocamento(tt, inicio_movimento, final_movimento)> }
          #end
          #declare j = j + 1;
        #end
        #declare i = i + 1;
    #end
  }
#end

#include "eixos.inc"

union{
  object{ eixos(3.00) }

  object{ chao  translate < 0,0,-5 > texture{ tx_verde } }

  union {
    object { secao(5, 10, clock, 0, 0.125) texture {tx_marrom} }
    object { secao(5, 10, clock, 0, 0.125) translate <0,6,6> texture {tx_marrom} }
    object { secao(5, 10, clock, 0.125, 0.25) texture {tx_marrom}  translate <10.5,0,0>}
    object { secao(5, 10, clock, 0.125, 0.25) translate <10.5,6,6> texture {tx_marrom} }
    object { escada(22) scale(0.5) translate <10,0,0> texture {tx_bege} }
  }

  union {
    object { escada(22) scale(0.5) translate <-0.5,0,0> texture {tx_bege} }
    object { secao(11, 15, clock, 0.75, 1.0) translate <-15.5,0,0> texture {tx_marrom} }
    rotate 90*z
 }

  union {
         object { escada(22) scale <1,0.5,0.5> texture {tx_bege} }
         object { secao(11, 17, clock, 0.5, 0.72) translate<1,0,0> texture {tx_marrom} }
         object { escada(22) scale(0.5) translate <18,0,0> texture {tx_bege} }
    object { secao(11, 3, clock, 0.72, 0.75) translate <18.5,0,0> texture {tx_marrom} }
    rotate 180*z translate <20.5,-15.5,0>
  }

  union {
         object { secao(11, 8, clock, 0.25, 0.375) texture {tx_marrom} }
    object { secao(11, 7, clock, 0.375, 0.5) translate <8.5,0,0> texture {tx_marrom} }
    object { escada(22) scale(0.5) translate <8,0,0> texture {tx_bege} }
    rotate -90*z translate <20.5, 0, 0>
  }

}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 30.0;
#declare dir_camera = < 10.00, -15.00, 2.00 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)