// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2010-03-04 15:44:01 by stolfi

// ======================================================================
// CORES E TEXTURAS

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

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

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

// ======================================================================

// Partes da cena: 

// orelha esquerda  

#declare caixa_fora =
  object {
    box{ <0,0,0>, <1,4,2> }

    translate < 0,0,0 >
    texture{ tx_bola }
  }

#declare caixa_dentro =
  object {
    box{ <0,0,0>, <1.2,3.8,1.8> }

    translate < 0,0,0 >
    texture{ tx_bola }
  }
  
#declare caixa = 
  difference { 
    object { caixa_fora translate < 0,0,0 > }
    object { caixa_dentro translate < -0.1,0.1,0.1 > }
  }

#declare pino = 
  cylinder{
    < 0, 0, 0 >,
    < 0, 0, 1 >,
    0.1
    texture{ tx_bola }
  }

#declare rosca = 
  cylinder{
    < 0, 0, 0 >,
    < 0, 0, 0.3 >,
    0.2
    texture{ tx_fosca }
  }

#macro bit_normal(valor)
  union {
    object{ pino translate < 0,0,0 > }
    #if (valor = 0)
      object{ rosca translate < 0,0,0 > }
    #else
      object{ rosca translate < 0,0,0.7 > }    
    #end
  }
#end

#macro bit(valor, defeito)
  #if (defeito)
    object{ pino }
  #else
    object{ bit_normal(valor) }
  #end
#end

#macro fileira(n, valor) // n de bits, valor decimal
  #local i = 0;
  #local atual = 0;

  union {  
   #while (i < n)
      #local atual = mod(valor,2);
    
      object { bit(atual,0) translate < 0,-1*i,0 > }
    
      #local valor = int(valor/2);
      #local i = i+1;
    #end
  }
  
#end

#declare valores = array[5];
#declare valores[0] = 1;
#declare valores[1] = 5;
#declare valores[2] = 10;
#declare valores[3] = 7;
#declare valores[4] = 13;

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

#end

#include "eixos.inc"

// Aqui está a cena, finalmente:

union{
  object{ eixos(3.00) }
  
  // CONTROLE POR AQUI O NUMERO DE LINHAS (M) E O NUMERO DE COLUNAS (N)
  // POIS AFETA A POSICAO NA TELA
  #local m = 4;
  #local n = 4;
  
  object{ abaco(m,n,valores) translate< 0,0,1.5*(m-1) > }
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 10;
#declare dir_camera = < 14.00, 0.00, 4.00 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)