// ======================================================================
// CORES E TEXTURAS

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

#declare tx_liquid = 
  texture {
    pigment { color rgb <1.00, 0.80, 0.10> filter 0.7 }
    finish { diffuse 0.2 reflection 0.8 }
  }

#declare tx_vidro = 
  texture{
    pigment { color rgb < 0.85, 0.95, 1.00 > filter 0.70 }
    finish { diffuse 0.03 reflection 0.25 ambient 0.02 specular 0.25 roughness 0.005 }
  }


#declare tx_board =
  texture{
    pigment { checker color rgb 2*< 0.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish { diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#declare tx_piece_body = 
  texture{
    pigment {
      marble
      color_map {
        [0.0 color rgb <0.2, 0.2, 0.2>]
        [0.4 color rgb <0.5, 0.5, 0.5>]
        [1.0 color rgb <0.9, 0.9, 0.9>]
      }
    }

    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_piece_base = 
  texture{
    pigment {
      wood
      color_map {
        [0.0 color rgb 6*<0.1, 0.08, 0.05>]
        [1.0 color rgb 3*<0.3, 0.2, 0.15>]
      }
    }

    finish{ diffuse 0.9 ambient 0.1 }
  }

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

#declare raio = 2.000;
#declare feet_distance = 2.5;
#declare foot_height = 2;

// Partes da cena:
#declare pawn =
  union {
    cylinder {
      <0, 0, 0>, <0, 0, 0.4>, 0.8
      texture { tx_piece_base }
    }

    cone {
      <0, 0, 0.4>, 0.8
      <0, 0, 2.2>, 0.2
    }

    sphere {
      <0, 0, 2.2>, 0.5
    }

    texture { tx_piece_body }
  }

#declare queen =
  union {
    cylinder {
      <0, 0, 0>, <0, 0, 0.4>, 0.8
      texture { tx_piece_base }
    }

    cylinder {
      <0, 0, 0.4>, <0, 0, 0.6>, 0.8
    }

    cylinder {
      <0, 0, 0.6>, <0, 0, 0.8>, 0.6
    }

    cylinder {
      <0, 0, 0.8>, <0, 0, 1.0>, 0.4
    }

    cylinder {
      <0, 0, 1>, <0, 0, 1.8>, 0.25
    }

    cylinder {
      <0, 0, 1.8>, <0, 0, 2>, 0.6
    }

    cylinder {
      <0, 0, 2>, <0, 0, 2.2>, 0.5
    }

    cylinder {
      <0, 0, 2.2>, <0, 0, 2.4>, 0.4
    }

    cone {
      <0, 0, 2.4> 0.2,
      <0, 0, 3>, 0.5
    }

    texture { tx_piece_body }
  }

#macro board (m, n)
  #declare i = 0;
  union {
    #while(i < m)
      disc {
        <0, 0, 0>, <0, 0, 1>, i + 2, i + 1
        texture {
          pigment {
            #if (mod(i, 2) = 0)
              function { mod(ceil((atan2(x, y) + (pi / 2)) * n / (pi * 2)), 2) = 0 }
            #else
              function { mod(ceil((atan2(x, y) + (pi / 2)) * n / (pi * 2)), 2) != 0 }
            #end
            color_map { 
              [ 0.0  color rgb <0.2, 0.2, 0.2> ]
              [ 0.5  color rgb <0.2, 0.2, 0.2> ]
              [ 0.5  color rgb <0.9, 0.3, 0.2> ]
              [ 1.0  color rgb <0.9, 0.3, 0.2> ]
            }
          }

          finish { diffuse 0.9 ambient 0.1 }
        }
      }

      #declare i = i + 1;
    #end

    cylinder {
      <0, 0, -0.5>, <0, 0, -0.0000001>, m + 1.1
      texture { tx_piece_base scale 0.1 rotate 87*x translate <5, 0, 10 > }
    }

    #for (coord_y, 0, m - 1)
      #for (coord_x, 0, n - 1)
        #declare section_value = 2 * pi / n;
        #declare angle_value = section_value * (coord_x + 0.5);
        #declare translate_value = <(coord_y + 1.5) * cos(angle_value), (coord_y + 1.5) * sin(angle_value), 0>;

        #if (mod(coord_x, 6) = 0 & mod(coord_y, 2) = 0)
          object {
            pawn
            scale 0.4
            translate translate_value
          }
        #end

        #if (mod(coord_x, 6) = 1 & mod(coord_y, 3) = 2)
          object {
            queen
            scale 0.4
            translate translate_value
          }
        #end
      #end
    #end
  }
#end

#include "eixos.inc"

union {
  // object { pawn }
  // object { queen }

  object { board(5, 12) }
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 1.00 >;
#declare raio_cena = 8.0;
#declare dir_camera = < 14.00, 7.00, 9.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)