// Last edited on 2003-04-12 06:52:43 by stolfi
// MC930 - Trabalho prático 5 - 1s2003
// Artur Manoel Passos RA 001388

#include "colors.inc"

background{ SummerSky }

camera {
  location  <  0, -0.5, -30.00 >
  right     <  0.60, 0.00, 0.00 >
  up        <  0.00, 0.00, 0.20 >
  sky       <  0.00, 1.00, 0.00 >
  look_at   <  0.00, 0.00, 50.00 >
} 

light_source {
  100*< 0.00, 15.00, 4.00 >
  color rgb 0.5*< 1,1,1 >
}

light_source {
  100*< 5.00, 15.00, -15.00 >
  color rgb 1.3*< 1,1,1 >
}

light_source {
  100*< -5.00, 15.00, -20.00 >
  color rgb 1.1*< 1,1,1 >
}

// Probabilidade de desenhar peça numa posição válida, 
//   quanto maior o valor, maior a prob. de aparecer figura
#declare PROB_1 = 0.4;

// Probabilidade de ser esfera (e não cubo), 
//   quanto maior o valor, maior a prob. de ser esfera
#declare PROB_2 = 0.5;


#declare tx1 =
  texture {
    pigment { Silver }
    finish { diffuse 0.8 specular 0.1 roughness 0.005 ambient 0.2 }
  }

#declare i = -3;

#declare gerador = seed(1234517);

# while (i < 4)                                  // Secao

 box { <7*i-0.3, -5, 30>, <7*i+0.3, 4, 350> pigment {White} }     

    #declare altura = -5;
    #while (altura <5) 							// Prateleiras da esquerda
       #if (altura>-5)  						// Nao "desenha" a prateleira do nivel do solo
         box { <7*i-0.3-1.7, altura-0.2, 30>, <7*i-0.3, altura, 350> pigment {White} finish { diffuse 0.7 ambient 0.3 } }
       #end

       #declare prof = 30.9;
       #while (prof<349) 
         #declare rand1 = rand(gerador);
	 #declare rand2 = rand(gerador);
	 #if (rand1<PROB_1)  						// Se coloca ou nao o objeto
           #declare R = rand(gerador); 					// Tom do vermelho
           #declare G = rand(gerador); 					// Tom do verde
           #declare B = rand(gerador); 					// Tom do azul
           #if (rand2<PROB_2) 						// Se é cubo ou esfera
	     sphere{ <7*i-0.3-0.85, altura+0.6, prof >, 0.6 pigment { color rgb <R,G,B> } finish { diffuse 0.7 ambient 0.3 }}
           #else 
	     box{ <7*i-0.3-0.85-0.6, altura, prof-0.6>, <7*i-0.3-0.85+0.6, altura+1.2, prof+0.6> pigment { color rgb <R,G,B> } finish { diffuse 0.7 ambient 0.3 } }
           #end
         #end
         #declare prof = prof + 2;
       #end
       #declare altura = altura + 3;
    #end

    #declare altura = -5;
    #while (altura <5) 							// Prateleiras da direita
       #if (altura>-5)  						// Nao "desenha" a prateleira do nivel do solo
         box { <7*i+0.3, altura-0.2, 30>, <7*i+0.3+1.7, altura, 350> pigment {White} finish { diffuse 0.7 ambient 0.3 } }
       #end
       #declare prof = 30.9;
       #while (prof<349) 
         #declare rand1 = rand(gerador);
	 #declare rand2 = rand(gerador);
	 #if (rand1<PROB_1)  						// Se coloca ou nao o objeto
           #declare R = rand(gerador); 					// Tom do vermelho
           #declare G = rand(gerador); 					// Tom do verde
           #declare B = rand(gerador); 					// Tom do azul
           #if (rand2<PROB_2) 						// Se é cubo ou esfera
	     sphere{ <7*i+0.3+0.85, altura+0.6, prof >, 0.6 pigment { color rgb <R,G,B> } finish { diffuse 0.7 ambient 0.3 }}
           #else 
	     box{ <7*i+0.3+0.85-0.6, altura, prof-0.6>, <7*i+0.3+0.85+0.6, altura+1.2, prof+0.6> pigment { color rgb <R,G,B> } finish { diffuse 0.7 ambient 0.3 } }
           #end
         #end
         #declare prof = prof + 2;
       #end
       #declare altura = altura + 3;
    #end

 #declare i = i + 1;
#end

plane {
  y, -5
  texture {tx1}
}