// Last edited on DATE TIME by USER
// Processed by remove-cam-lights

#include "colors.inc"
#include "stones.inc"

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

#declare tx_xadrez =
  texture{
    pigment{ checker color rgb < 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_stone =
  texture{ T_Stone15 }

#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 chao =
  box{ <-100,-100,-1>, <+100,+100,0> }

#include "eixos.inc"

#declare RANDGEN = seed(1134);

#declare torre =
  union {
    cone { <0, 0, 0>, 3, <0, 0, 10>, 2 }
    difference {
      cylinder { <0, 0, 10>, <0, 0, 13>, 3 }
      union {
        cylinder { <0, 0, 11>, <0, 0, 14>, 2 }
        #local ang = 0;
        #while (ang < 360)
          box { <0, -0.5, 12>, <8, 0.5, 15> rotate <0, 0, ang> }
        #local ang = ang + 45;
        #end
      }
    }
    cylinder { <0, 0, 11>, <0, 0, 18>, 0.1 texture { tx_vidro } }
    box { <-0.07, 0, 16>, <0.07, 2, 18> texture { tx_vidro } }

  }

#macro castelo(L)
  union {
    #local M = 1+int(3*rand(RANDGEN));

    #local N = 1+int(3*rand(RANDGEN));
    #local V = pow(3, L+1)*2;
    #local W = M*V;
    #local H = N*V;
    object { torre translate <-H/2, -W/2, 0> }
    object { torre translate <-H/2, W/2, 0> }
    object { torre translate <H/2, -W/2, 0> }
    object { torre translate <H/2, W/2, 0> }
    #local W_wall = 0.3;
    difference {
      box { <-H/2-W_wall, -W/2-W_wall, 0>, <H/2+W_wall, W/2+W_wall, 9> }
      box { <-H/2+W_wall, -W/2+W_wall, -1>, <H/2-W_wall, W/2-W_wall, 10> }
    }
    #if (L > 0)
      #local i = 0;
      #while (i < M)

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

          object{ castelo(L-1) scale <0.7, 0.7, 0.9> translate <(j+0.5)*V-H/2, (i+0.5)*V-W/2, 0> }

        #local j = j+1;
        #end

      #local i = i+1;
      #end

    #end
  }
#end

union{

  object{ chao  translate < 0,0,0 > texture{ tx_xadrez } }

  object{ castelo(2) texture { tx_stone } }

}

#include "camlight.inc"
#declare centro_cena = < -20.00, -20.00, -30.00 >;
#declare raio_cena = 170.0;
#declare dir_camera = < 14.00, 7.00, 10.00 >;
#declare dist_camera = 200.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)