// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2017-05-07 20:10:09 by stolfilocal

#include "colors.inc"
#include "shapes.inc"

#declare component_color =
  texture {
    pigment { color rgb <0.2, 0.2, 0.2> }
  }

#declare die = seed(91);

#declare Chambers = array[10000];

#macro Make_Chamber(Index)
  #local Length = 0.5 + 1.3 * rand(die);
  #local BaseX = -7.0 + 15.0 * rand(die);
  #local EndX = BaseX + Length;
  #local BaseY = -7.0 + 15.0 * rand(die);
  #local EndY = BaseY + Length;
  #local BaseZ = 1.5 + 9.0 * rand(die);
  #local EndZ = BaseZ + Length;

  #local Center = <(BaseX + EndX)/2, (BaseY + EndY)/2, (BaseZ + EndZ)/2>;
  #declare Chambers[Index] = Center;

  box {
    <BaseX, BaseY, BaseZ>,
    <EndX, EndY, EndZ>
    texture { component_color }
  }
#end

#macro Make_Chambers(ChamberCount)
  #local Index = 1;

  #for (Index, 1, ChamberCount, 1)
    object { Make_Chamber(Index - 1) }
  #end
#end

#macro Make_Tunnel(StartCenter, EndCenter)
  cylinder {
    EndCenter,
    StartCenter,
    0.2
    texture { component_color }
  }
#end

#macro Mine(ChamberCount, TunnelCount)
  Make_Chambers(ChamberCount)

  #local TunnelIndex = 1;

  #for (TunnelIndex, 1, TunnelCount, 1)
    #local TunnelStart = int(ChamberCount * rand(die));
    #local TunnelEnd = int(ChamberCount * rand(die));

    #if (TunnelStart != TunnelEnd)
      Make_Tunnel(Chambers[TunnelStart], Chambers[TunnelEnd])
    #end
  #end
#end

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

camera {
  location <5, 7, -8>
  look_at <2, 3, 2>
}

light_source { <2, 4, -3> color White }

Mine(50, 50)