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

#declare steel_1 = // aço
  texture{
    pigment{ color rgb < 0.70, 0.70, 0.70 > }
    finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.1 specular 0.2 roughness 0.5}
  }

#declare tx_2 = 
  texture{
    pigment{ color rgb < 0.30, 0.30, 0.30 > }
    finish{ diffuse 0.5 ambient 0.1 brilliance 1 reflection 0.15 specular 0.2 roughness 0.5}
  }


#declare wood_1 = // wood_1
  texture{
    pigment{ color rgb < 0.52, 0.37, 0.26 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.05 }
  }

#declare tx_4 = 
  texture{
    pigment{ color rgb < 0.25, 0.59, 0.04 > }
    finish{ diffuse 0.3 ambient 0.1 specular 0.5 roughness 1 }
  }


#macro hiperpeao (posX, posY, posZ)
  #local base = cone {
    <posX, posY, posZ>, 1.0 // <x, y, z>, center & radius of one end
    <posX, posY, posZ+1>, 0.5 // <x, y, z>, center & radius of the other end
  }
  #local pescoco = cylinder {
    <posX, posY, posZ+1>, <posX, posY, posZ+2>, 0.5 // center of one end, center of other end, radius
    open // remove end caps
    
  }
  #local cabeca = box {
    <posX-0.5, posY-0.5, posZ+2>, <posX+0.5, posY+0.5, posZ+3> // <x, y, z> near lower left corner, <x, y, z> far upper right corner
    
  }
  union {
    object {base texture{steel_1}}
    object {pescoco texture{steel_1}}
    object {cabeca texture{steel_1}}
  }
#end

#macro hiperdama (posX, posY, posZ)
  #local raio = 0.7;
  #local base = cone {
    <posX, posY, posZ>, 1.0 // <x, y, z>, center & radius of one end
    <posX, posY, posZ+1>, 0.5 // <x, y, z>, center & radius of the other end
  }
  #local colar = cylinder {
    <posX, posY, posZ+1>, <posX, posY, posZ+1.2>, 1 // center of one end, center of other end, radius
     // remove end caps
    
  }
  #local pescoco = cylinder {
    <posX, posY, posZ+1.2>, <posX, posY, posZ+2.5>, 0.5 // center of one end, center of other end, radius
    open // remove end caps
    
  }
  #local cabeca = sphere {
    <posX, posY, posZ+2.5+raio/2>, raio // <x, y, z>, radius
    
  }
  union {
    object {base texture{steel_1}}
    object {colar texture{steel_1}}
    object {pescoco texture{steel_1}}
    object {cabeca texture{steel_1}}
  }
#end

#macro casa (cor, raio, posX, posY)
  #local cela = cylinder {
      <posX, posY, 0>, <posX, posY, -0.1>, raio
      texture {
        pigment{ color rgb < 0+cor, 0+cor, 0+cor> }
      }
    }
  object{cela}
#end

#macro tabuleiro (m, n)
  #local posX = 0;
  #local posY = 0;

  #local alfa = radians(360)/n;
  #local raio = 3;
  #local angulo = radians(0);


  #local i = 0;
  #local diff_r = 3;

  #local cor = 0;

  #while (i < m)
    #local angulo = 0;

    #local j = 0;
    #while (j < n)

    #local posX = raio*cos(angulo);
    #local posY = raio*sin(angulo);

    #if (mod(i + j, 2) = 0)
      #local cor = 0;
    #else
      #local cor = 1;
    #end

    casa(cor, 1.5, posX, posY)

    #local angulo = angulo + alfa;
    #local j = j + 1;

    #end

  #local raio = raio + diff_r;
  #local i = i + 1;
  #end
#end

#macro posicionar (m, n)
  #local posX = 0;
  #local posY = 0;

  #local alfa = radians(360)/n;
  #local raio = 3;
  #local angulo = radians(0);


  #local i = 0;
  #local diff_r = 3;

  #while (i < m)
    #local angulo = 0;

    #local j = 0;
    #while (j < n)

    #local posX = raio*cos(angulo);
    #local posY = raio*sin(angulo);

    #if (mod(i + j, 3) = 0)
      hiperpeao(posX, posY, 0)
    #else
      #if(mod(i + j, 7) = 0)
        hiperdama(posX, posY, 0)
      #end
    #end

    #local angulo = angulo + alfa;
    #local j = j + 1;

    #end

  #local raio = raio + diff_r;
  #local i = i + 1;
  #end


#end

#local nfileiras = 10;
#local ncasas = 20;

union{
  tabuleiro (nfileiras,ncasas)

  posicionar(nfileiras, ncasas)
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 3.5*nfileiras + 4;
#declare dir_camera = < 10.00, 5.00, 4.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)