// Last edited on 2007-04-01 20:18:20 by stolfi
// Processed by remove-cam-lights

#declare tabsize = 16;
#declare casasize = 4.0;

#declare randvar = seed(032883);

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

#declare marrom_claro = 
  texture {
    pigment { color rgb < 1.00, 0.95, 0.90 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.2 }
  }
  
#declare marrom_escuro = 
  texture {
    pigment { color rgb < 0.50, 0.40, 0.40 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.2 }
  }
  
#declare amarelo_escuro = 
  texture {
    pigment { color rgb < 0.60, 0.60, 0.20 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.2 }
  } 

#declare branco = 
  texture {
    pigment { color rgb < 0.95, 0.95, 0.95 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.2 }
  }
  
#declare preto = 
  texture {
    pigment { color rgb < 0.40, 0.40, 0.40 > }
    finish { diffuse 0.8 specular 0.2 roughness 0.005 ambient 0.2 }
  }

#declare casa =
 box {
  < -(casasize / 2), -(casasize / 2), -2.0 >
  <  (casasize / 2),  (casasize / 2), 0.0 >
 }

#declare tabuleiro =
union {
#declare i = 0;
#while (i < tabsize)
 #declare j = 0;
 #while (j < tabsize)
 object {
   
   casa  
   translate < casasize * i, casasize * j, 0 >
  #if (mod( i + j , 2) = 0)
   texture { marrom_claro }
  #else
   texture { marrom_escuro }
  #end
 }
 
 #declare j = j + 1;
 #end
#declare i = i + 1;
#end
 
 box {
  <  -4.0, -4.0,  -0.1 >
  <  tabsize * casasize, tabsize * casasize, -1.5 >
  texture { amarelo_escuro }
 }
 box {
  <  -3.0, -3.0,  -1.5 >
  <  tabsize * casasize - 1, tabsize * casasize - 1, -2.5 >
  texture { amarelo_escuro }
 }
 box {
  <  -4.0, -4.0,  -2.5 >
  <  tabsize * casasize, tabsize * casasize, -4.0 >
  texture { amarelo_escuro }
 }
}

#declare peao =
 union {
  cylinder 
  {
   <  0.0,  0.0,  0.0 >,
   <  0.0,  0.0,  0.5 >,
   1.5
  }  
  cone {
   < 0.0, 0.0, 0.5 > 1.5
   < 0.0, 0.0, 2.0 > 0.6
  }
  cylinder 
  {
   <  0.0,  0.0,  2.0 >,
   <  0.0,  0.0,  3.0 >,
   0.6
  }
  cylinder 
  {
   <  0.0,  0.0,  3.0 >,
   <  0.0,  0.0,  3.5 >,
   0.5
  }
  cylinder 
  {
   <  0.0,  0.0,  3.5 >,
   <  0.0,  0.0,  4.5 >,
   0.6
  }
  cylinder 
  {
   <  0.0,  0.0,  4.7 >,
   <  0.0,  0.0,  5.3 >,
   0.8
  }
  cylinder 
  {
   <  0.0,  0.0,  5.3 >,
   <  0.0,  0.0,  5.6 >,
   0.7
  }
  cylinder 
  {
   <  0.0,  0.0,  5.6 >,
   <  0.0,  0.0,  6.0 >,
   0.8
  } 
 
 }
 
#declare torre =
 union 
 {  
  cylinder 
  {
   <  0.0,  0.0,  0.0 >,
   <  0.0,  0.0,  2.0 >,
   1.5
  } 
  cylinder 
  {
   <  0.0,  0.0,  2.0 >,
   <  0.0,  0.0,  3.0 >,
   1.3
  }
  difference
  { 
   cylinder 
   {
    <  0.0,  0.0,  3.0 >,
    <  0.0,  0.0,  6.0 >,
    1.5
   }
   union
   { 
    cylinder 
    {
     <  0.0,  0.0,  5.0 >,
     <  0.0,  0.0,  6.5 >,
     1.0
    }
    box
    {
     < -1.6, -0.5, 5.0 >
     <  1.6,  0.5, 6.5 > 
    }
    box
    {
     < -0.5, -1.6, 5.0 >
     <  0.5,  1.6, 6.5 > 
    }
   }
   
  }
 }
 
#declare rei =
 union {
  cylinder 
  {
   <  0.0,  0.0,  0.0 >,
   <  0.0,  0.0,  0.5 >,
   1.5
  }  
  cone {
   < 0.0, 0.0, 0.5 > 1.5
   < 0.0, 0.0, 2.0 > 0.6
  }
  cylinder 
  {
   <  0.0,  0.0,  2.0 >,
   <  0.0,  0.0,  3.7 >,
   0.6
  }
  cylinder 
  {
   <  0.0,  0.0,  3.7 >,
   <  0.0,  0.0,  4.0 >,
   0.8
  }
  cylinder 
  {
   <  0.0,  0.0,  4.0 >,
   <  0.0,  0.0,  4.5 >,
   0.6
  }  
  cone {
   < 0.0, 0.0, 4.5 > 0.6
   < 0.0, 0.0, 6.0 > 1.0
  }
  box {
   < -0.6, -0.2, 6.4 >
   <  0.6,  0.2, 6.8 >
  }
  box {
   < -0.2, -0.2, 6.0 >
   <  0.2,  0.2, 7.2 >
  }
 
 }

object { tabuleiro }

#declare i = 0;
#declare r = 0;
#while (i < tabsize)
 #declare j = 0;
 #while (j < tabsize)
 #if (mod( i + j , 2) = 0)
 
  #if (rand(randvar) > 0.7)
  
  object {
   #declare s = rand(randvar);
   #declare c = rand(randvar);
   
   #if (s > 0.9 & r < 2)
    rei
    #if (r = 1)
     texture { branco }
    #else
     texture { preto }
    #end
    
    #declare r = r + 1;    
    
   #else
    #if (s > 0.7)
     torre
    #else
     peao
    #end
    
    #if (rand(randvar) < 0.5)
     texture { branco }
    #else
     texture { preto }
    #end
   #end
   translate < casasize * i, casasize * j, 0 >
  }
  #end
 
 #end
 
 #declare j = j + 1;
 #end
#declare i = i + 1;
#end

// Original camera parameters:
// #local cam_ctr = (<(tabsize * casasize / 2),(tabsize * casasize / 2),0.00>)
// #local cam_vec = ((<(tabsize * casasize / 2) - 15,-90,40>)-(<(tabsize * casasize / 2),(tabsize * casasize / 2),0.00>))
// #local cam_sky = z

#include "camlight.inc"
#local RR = (tabsize * casasize / 2);
camlight((<RR,RR,0.00>),<10,10,10>,90.0,z,1.0)