// MC930 - Exercicio 8 - Macros e definicoes recursivas
// 23/11/2004
// Pablo Augusto Verissimo - RA 002266

#include "colors.inc"
#include "metals.inc"
#include "stones.inc"
#include "textures.inc"
#include "skies.inc"

// ======================================================================
// CÂMERA 

camera {
  location  < 50,50,50 >  // 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   <  0, 0, 30 >  // 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 {
  10 * < +50.0, +30.0, +50.0 >              // Posição da lâmpada.
  color rgb 1.2 * < 1.00, 1.00, 1.00 >   // Intensidade e corda luz.
} 

light_source {
  10 * < +50.0, -10.0, +10.0 >             // Posição da lâmpada.
  color rgb 0.8 * < 0.90, 0.70, 0.80 >   // Intensidade e corda luz.
} 

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

background{ color rgb < 0.9, 0.9, 0.9 > }

//plane { z,-5
  //texture {T_Grnt24}	
//}

#declare raiz = 
	sphere { 
		<0,0,0>,1
		pigment { Blue }
	}

#declare G = seed(558456);

#macro Arvore_Loca (i)
	union {
		cylinder {
			<0,0,0>,<0,0,4>,0.3
			pigment { Red }
		}
		cylinder {
			<0,0,0>,<0,4,0>,0.3
			pigment { Red }
		}
		cylinder {
			<0,0,0>,<4,0,0>,0.3
			pigment { Red }
		}
		object { raiz }		
		object { raiz translate <0,0,4> }
		object { raiz translate <4,0,0> }
		object { raiz translate <0,4,0> }		
		#if (i > 0)
			object { 
				Arvore_Loca (i-1)
				#local j = rand(G);
				#if (j < 0.33)
					rotate <20*j,20*j,20*j> 
					translate <0,0,4>
				#else 
					#if (j > 0.66)
						rotate <20*j,10*j,20*j> 
						translate <4,0,0>
					#else
						rotate <20*j,10*j,30*j>
						translate <0,4,0>
					#end
				#end				
			}
		#end
	}
#end

#declare desenho = 
	union {
		object { 
			Arvore_Loca (50) 
		}
	}

//****************************    
//Aqui está a cena, finalmente:
//****************************

union {
	object { desenho }
}