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

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

#declare tx_plastico =
  texture{
    pigment{ color rgb < 0.10, 0.80, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_fosca_escura =
  texture{
    pigment{ color rgb < 0.3, 0.30, 0.40 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_fosca_vermelho =
  texture{
    pigment{ color rgb < 0.9, 0.30, 0.3 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_caixa =
  texture{
    pigment{ color rgb < 0.80, 0.70, 0.60 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_fosca =
  texture{
    pigment{ color rgb < 0.70, 0.70, 0.80 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_bota =
  texture{
    pigment{ color rgb < 92, 51, 23 >/255 }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_espelho =
  texture{
    pigment{ color rgb < 0.80, 0.80, 0.85 > }
    finish{ diffuse 0.2 reflection 0.1*< 0.80, 0.80, 0.85 > ambient 0.1 }
  }

#declare tx_vidro =
  texture{
    pigment{ color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish{ diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 roughness 0.005 }
  }

#declare tx_nariz =
  texture{
    pigment{ color rgb < 0.9, 0.30, 0.4 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#macro interruptor (valor,defeito)
  union{
    box{
      <-1.5,-2.5,0>,
      <1.5,2.5,0.5>
      texture{tx_fosca_escura}
    }

    box{
      <-1,-2,0.5>
      <1,0,0.6>
      texture{tx_fosca_vermelho}
    }
    #if(!defeito)
    prism{
      0, 2, 4,
      <0,0>, <2,0>, <2,1.3*(1-valor)>, <0,0>
      texture{tx_fosca_vermelho}
      rotate -90*z
      translate <-1,0,0.6>
    }
    #end

    box{
      <-1,0,0.5>
      <1,2,0.6>
      texture{tx_fosca}
    }
    #if(!defeito)
    prism{
      0, 2, 4,
      <0,0>, <2,0>, <2,1.3*valor>, <0,0>
      texture{tx_fosca}
      rotate 90*z
      translate <1,0,0.6>
    }
    #end
  }

#end

#macro fileira(numbits, valor,prob)
  #local i=0;
  #local r = int(valor);
  #local f = valor -r;

union{
  #while(i<numbits)

    #if(rand(roleta)<prob)
      #local defeito=1;
    #else
      #local defeito=0;
    #end

    #local vb = mod(r,2);
    #if(vb=0)
      #local bit = f;
      #local f=0;
    #else
      #local bit = 1-f;
    #end

    object{interruptor(bit,defeito) translate<0,3*(numbits-1) - 6*i,0>}
    #local r=int(r/2);
    #local i = i+1;
  #end
  }

#end

#macro caixa(m,n,valores,prob)
  #local i=0;
  union{
    union{
    #while(i<m)
      object{fileira(n,valores[i],prob) translate<-2*(m-1) + 4*i,0,0>}
      #local i = i+1;
    #end
    translate<0,0,1>
    }
    box{<-2*(m-1)-3,-3*(n-1)-4,0> <2*(m-1)+3,3*(n-1)+4,1> texture{tx_caixa}}
  }
#end

#include "eixos.inc"

#declare chao =
  box{ <-15,-15,-1>, <+15,+15,0> }

#declare valores1 = array[4] {10,0,7,13}
#declare valores2 = array[4] {11,3,15,9}

#declare valores = array[4];

#local i = 0;
#while(i<4)
  #local aux = 2*abs(0.5-clock);
  #local valores[i] = (valores1[i]*(1-aux) + valores2[i]*aux);
  #local i = i+1;
#end

#declare roleta = seed(447);

union{

  object{caixa(4,4,valores,0.2) }

}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 26;

#declare dir_camera = < 5.00, -3.0+(6.00*2*abs(0.5-clock)), 2.50 >;

#declare dist_camera = 26.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)