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

#include "textures.inc"
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 =
  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.7*< 1.00, 0.85, 0.30 > 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_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 tx_marrom =
  texture{
    pigment{ color rgb < 0.92, 0.51, 0.23 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_marrom_claro =
  texture{
    pigment{ color rgb < 1.02, 0.71, 0.23 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_verde = //35,142,35
  texture{
    pigment{ color rgb < 0.35, 1.42, 0.35 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_verde_escuro = //47,79,47
  texture{
    pigment{ color rgb < 0.47,0.79, 0.47 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare caixaGrande =
  box{
        <0, 0, 0>,
    <1, 2, 0.5>
        }

#declare caixaPeq =
  box{
        <0, 0, 0>,
    <0.5, 1.6, 0.5>
        }

#declare caixa =
  box{
        <0, 0, 0>,
    <0.5, 0.5, 0.5>
        }

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

#include "eixos.inc"

#macro bit(valor, defeito)
        #if (defeito = 1)
                union {
                                difference {
                                        object{ caixaGrande texture{ tx_marrom_claro } }
                                        object{ caixaPeq translate < 0.25,0.25,0.1 >  texture{ tx_marrom_claro }}
                                }
                        }
        #else
                union {
                        difference {
                                object{ caixaGrande texture{ tx_marrom_claro } }
                                object{ caixaPeq translate < 0.25,0.25,0.1 > texture{ tx_marrom_claro } }
                        }
                        object{ caixa translate < 0.25,0.25+1.1*(1-valor),0.25 > texture{ tx_verde_escuro } }
                }
        #end
#end

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

#macro abaco(m,n,valores,probabilidade)
        #local i = 0;
        union {
                #while (i < m)
                        object{ fileira(n,valores[i],probabilidade) translate<0,i*2,0> }
                        #local i = i + 1;
                #end
        }
#end

#declare roleta = seed(417);

#declare prob = 0.00;
#declare m = 5;
#declare valores = array[m];
#declare valores[0] = (1-clock) * 10 + clock * 12;
#declare valores[1] = (1-clock) * 10 + clock * 15;
#declare valores[2] = (1-clock) * 1 + clock * 15;
#declare valores[3] = (1-clock) * 0 + clock * 1;
#declare valores[4] = (1-clock) * 2 + clock * 60;

#declare prob2 = 0.75;
#declare m2 = 10;
#declare valores2 = array[m2];
#declare valores2[0] = 1;
#declare valores2[1] = 2;
#declare valores2[2] = 3;
#declare valores2[3] = 4;
#declare valores2[4] = 5;
#declare valores2[5] = 6;
#declare valores2[6] = 7;
#declare valores2[7] = 8;
#declare valores2[8] = 9;
#declare valores2[9] = 0;

object{ abaco(m,6,valores,prob) scale <2,2,2> translate <-2,-2,-8> rotate -90 *x translate <+0,0,0.5*m+5> }

object{ eixos(3.00) }

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 25.0;
#declare dir_camera = < clock+0.00, 1.00-clock, 0.2 >;
#declare dist_camera = 25.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)