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

#include "colors.inc"

// CÂMERA 

camera {
  location  < 0,60.0 , -10.0 >  // Posição do observador.
  right     -0.75*x                // Largura RELATIVA da imagem.
  up        1.00*y                 // Altura RELATIVA da imagem.      
  sky       z                      // Qual direção é "para cima"?
  look_at   <  3.00, 0.00, -10.00 >  // Para onde a câmera está apontando.
} 
// Nota: os parâmetros "right" e "up" devem ter a mesma proporção
// que os parâmetros ${WIDTH} e ${HEIGHT} no Makefile.

// ======================================================================
// FONTES DE LUZ

light_source {
  < 0.0, +25.0, 15.0 >              // Posição da lâmpada.
  color rgb 1.2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < 0.0, 20.0, 70.0 >             // Posição da lâmpada.
  color rgb 2.0 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
   < 1.0, 1.0, -1.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

// ======================================================================
// DESCRIÇÃO DA CENA 

background{ color rgb Gray }

#declare tinta_azul = 
  texture {
    pigment { color rgb < 0.00, 0.00, 1.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare tx_espelho = 
  texture {
    pigment { color rgb < 0.00, 1.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare tinta_vermelha = 
  texture {
    pigment { color rgb < 1.00, 0.00, 0.00 > }
    finish { diffuse 0.5 specular 0.5 roughness 0.005 ambient 0.1 }
  }

#declare cor_espelho = <0.00, 0.00, 1.00>;

#declare tx_espelho2 =
	texture{
		pigment{ rgb cor_espelho }
		finish{
			ambient 0.05 diffuse 0.05
			reflection cor_espelho
			specular 0.20 roughness 0.05
		}
	}
#declare cor_cristal = < 1, 0, 0>;

#declare tx_cristal =
	texture{
		finish{
			ambient 0.1 diffuse 0.1 reflection 0.25
			specular 1 roughness 0.001
		}
		pigment {color cor_cristal filter 1}
	}


#macro noh(geracao, n_geracoes, x_pai, y_pai, z_pai, lado)
    #if (n_geracoes > 0)
      #if (lado = 1)
	union{
	   cylinder{
		<x_pai, y_pai, z_pai>,
		<x_pai-pow(1.6,n_geracoes), y_pai, z_pai-4>,
		0.2
		texture{tx_cristal}		
	   }
	
	   sphere{
		<x_pai-pow(1.6,n_geracoes), y_pai, z_pai-4>,
		1
		texture{tx_espelho}
	   }
	   noh(geracao+1, n_geracoes-1,x_pai-pow(1.6,n_geracoes), y_pai, z_pai-4, 0)
 	   cylinder{
		<x_pai, y_pai, z_pai>,
		<x_pai+pow(1.6,n_geracoes), y_pai, z_pai-4>,
		0.2
		texture{tx_cristal}		
	   }

	   sphere{
		<x_pai+pow(1.6,n_geracoes), y_pai, z_pai-4>,
		1
		texture{tx_espelho}
	   }
	   noh(geracao+1, n_geracoes-1,x_pai+pow(1.6,n_geracoes), y_pai, z_pai-4, 1)

	}
      #else
	union{
	   cylinder{
		<x_pai, y_pai, z_pai>,
		<x_pai, y_pai-pow(1.6,n_geracoes), z_pai-4>,
		0.2
		texture{tx_cristal}		
	   }

	   sphere{
		<x_pai, y_pai-pow(1.6,n_geracoes), z_pai-4>,
		1
		texture{tx_espelho}
	   }
	   noh(geracao+1, n_geracoes-1,x_pai, y_pai-pow(1.6,n_geracoes), z_pai-4, 0)
 	   cylinder{
		<x_pai, y_pai, z_pai>,
		<x_pai, y_pai+pow(1.6,n_geracoes), z_pai-4>,
		0.2
		texture{tx_cristal}		
	   }

	   sphere{
		<x_pai, y_pai+pow(1.6,n_geracoes), z_pai-4>,
		1
		texture{tx_espelho}
	   }
	   noh(geracao+1, n_geracoes-1,x_pai, y_pai+pow(1.6,n_geracoes), z_pai-4, 1)

	}


      #end
    #end
#end  

sphere{
<0,0,0>, 1
texture {tx_espelho}
}
noh(0, 5, 0, 0, 0, 1)