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

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

#declare tx_red =
texture{
  pigment{ color rgb < 0.90, 0.20, 0.20 > }
  finish{ diffuse 0.8 ambient 0.4 specular 0.5 roughness 0.005 }
}

#declare tx_blue =
texture{
  pigment{ color rgb < 0.30, 0.30, 1.0 > }
  finish{ diffuse 0.8 ambient 0.5 specular 0.7777777 roughness 0.005 }
}

#declare tx_green =
texture{
  pigment{ color rgb < 0.20, 0.90, 0.20 > }
  finish{ diffuse 0.8 ambient 0.4 specular 0.5 roughness 0.005 }
}

#declare tx_steel =
texture{
  pigment { rgb <0.55, 0.5, 0.45> }
  finish { metallic ambient 0.1 diffuse 0.65 specular 0.85 roughness 0.01 reflection 0.45 brilliance 1.5}
}

#declare tx_black =
texture{
  pigment{ color rgb < 0.60, 0.30, 0.60 > }
  finish{ diffuse 0.5 ambient 0.2 }
}

#declare tx_glass =
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 zero = 0.0000001;
#declare rseed = seed(10);

#macro wall (L,W,H)
  box {<0,0,0>,<L,W,H> translate<-L/2,0,0> }
#end

#macro dentedWall (L,W,H,Ndents,Nlevels)
  #if (Nlevels>0)
    union {
      object {wall (L,W,H)}
      #local i=0;
      #local rate=(Ndents*2)-1;
      #local len = L/(2*rate);
      #while (i<Ndents)
        object {dentedWall (L/rate, W, H/rate, Ndents, Nlevels-1) translate <(-L/2)+len+i*2*(L/rate),0,H>}
        #local i=i+1;
      #end
    }
  #else
    sphere{<0,0,0>, 0} //Null object in the base case of recurssion
  #end
#end

#macro tower (H,R)
  cylinder {<0,0,0>, <0,0,H>, R}
#end

#macro castleWalls (L,W,H,Nlevels)
  union {
    #local Ndents = 2+int(8*rand(rseed));
    object {dentedWall (L,W,H,Ndents,Nlevels) rotate<0,0,90> translate <L/2,0,0>}
    object {dentedWall (L,W,H,Ndents,Nlevels) rotate<0,0,-90> translate <-L/2,0,0>}
    object {dentedWall (L,W,H,Ndents,Nlevels) translate <0,L/2,0>}
    object {dentedWall (L,W,H,Ndents,Nlevels) translate <0,-L/2,0>}
  }
#end

#macro castle (L,W,H,Ndents,Nlevels)
  union {
    #local s = 0.8;
    #local r = rand(rseed);
    object {castleWalls (L,W,H-r-r,Nlevels) texture {tx_blue}}
    object {castleWalls (L,W,H-r,Nlevels) scale <s,s,0> texture {tx_red}}
    object {castleWalls (L,W,H,Nlevels) scale <s*s,s*s,0> texture {tx_blue}}
    box {<0,0,0>, <L,L,W/2> translate <-L/2,-L/2,W> texture {tx_blue}}
  }
#end

#include "eixos.inc"
union {
  object {castle (10,0.5,5,7,3)}
  union {
    object {tower(5+int(5*rand(rseed)),1) translate<-1.5,0,0> }
    object {tower(5+int(5*rand(rseed)),1) translate<1.5,0,0> }
    object {tower(5+int(5*rand(rseed)),1) translate<0,1.5,0> }
    object {tower(5+int(5*rand(rseed)),1) translate<0,-1.5,0> }
    texture {tx_red}
  }

  scale <1,1,1>
}

#include "camlight.inc"
#declare centro_cena = < 0.00, 0.00, 0.00 >;
#declare raio_cena = 20;
#declare dir_camera = < 10, 20, 25 >;
#declare dist_camera = 16.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)