// 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.2 roughness 0.005 }
  }

#declare tx_verde =
  texture{
    pigment{ color rgb < 0.48, 0.99, 0.00 > }
  };

#declare tx_cinza_escuro =
  texture{
    pigment{ color rgb < 0.2, 0.2, 0.2 > }
  };

#declare tx_vermelho =
  texture{
    pigment{ color rgb < 1.00, 0.00, 0.00 > }
  }

#declare tx_marrom =
  texture{
    pigment{ color rgb < 0.92, 0.64, 0.51 > }
  };

#declare tx_branco =
  texture{
    pigment{ color rgb < 1, 1, 1 > }
  };

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

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

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

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#declare M = 5; //Num Quadros

#declare valores = array[M] {
        (1-clock)*10 + clock*11,
        (1-clock)*8 + clock*11,
        (1-clock)*6 + clock*11,
        (1-clock)*4 + clock*11,
        (1-clock)*2 + clock*11,
};

#declare valores2 = array[6] {1,3,5,7,9,11};

#declare roleta = seed(417);

#declare haste_con =
        cone{
                <0, 0, 0>, 0,
                <0, 0, 3>, 1
                texture{ tx_branco }
        }

#declare haste_esf =
  sphere{ < 0,0,0 >, 1
                texture{ tx_branco }
        }

#declare caixa=
        box{
                <+3,+1.5,0>,
                <-3,-1.5,-1>
                texture { tx_branco }
        }

#declare chao =
        box{
                <50, 50, 0>,
                <-50, -50, 0.5>
                texture { tx_verde }
        }

#declare haste_cil =
        cylinder {
                <0,0,0>,
                <0,0,1>,
                1
        }

#macro bit(rot, defeito)
        #local textura = tx_branco;

        #if (defeito = 1)
                #local textura = tx_verde;
        #end

        union{
                union{
                        object { haste_con texture { textura }}
                        difference {
                                object { haste_esf texture { textura }}
                                object { caixa texture { textura }}
                                translate <0,0,3>
                        }
                        translate<0,0,1>
                        rotate -25*rot *y
                }
                object { caixa translate<0,0,0.5> texture { tx_plastico }}
                object { haste_esf scale<0.8,0.8,0.8> translate <0,0,0.8> texture { textura }}
                difference {
                        object { haste_cil texture { tx_branco }}
                        object { haste_cil scale<0.8,0.8,1.5> translate<0,0,0.2>}
                }
        }
#end

#macro move_bit(valor, defeito)
                bit(valor*2 -1, defeito)
#end

#macro fileira(n, valor, p)
        #local i=0;
        #local r = int(valor);
        #local f = valor - r;
        union{
                #while (i < n)
                        #if (rand(roleta) <= p)
                                #local defeito = 1;
                        #else
                                #local defeito = 0;
                        #end
                        #local vv = mod(r,2);
                        #if (vv = 0)
                                object { move_bit(f, defeito) translate<0, i*-2.5, 0>}
                                #local f = 0;
                        #else
                                object { move_bit(1-f, defeito) translate<0, i*-2.5, 0>}
                        #end
                        #local i = i+1;
                        #local r = int(r/2);
                #end
        }
#end

#macro abaco(m,n,valor, prob)
        #local i=0;

        union{
                #while (i < m)
                        object { fileira(n, valor[i], prob) translate <6*i, 0, 0>}
                        #local i = i+1;
                #end
        }
#end

#include "eixos.inc"

union{

        object{ abaco(M, 4, valores, 0) scale<0.2,0.2,0.2> rotate 90 *z}

}

#include "camlight.inc"
#declare centro_cena = < 1, 2.5, 0.00 >;
#declare raio_cena = 5;
#declare dir_camera = < (1-clock)*(-3) + clock*3, clock*3, sin(pi*clock)*4.00 + 1 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)