// Exemplo de arquivo de descricao de cena para POV-ray
// Last edited on 2020-09-30 19:57:13 by jstolfi

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

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

#declare tx_plastico = 
  texture{
    pigment{ color rgb < 0.10, 0.80, 1.00 > }
    finish{ diffuse 0.8 ambient 0.1 specular 0.5 roughness 0.005 }
  }

#declare tx_fosca = 
  texture{
    pigment{ color rgb < 0.54, 0.80, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_espelho = 
  texture{
    pigment{ color rgb < 1.00, 0.85, 0.30 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

// ======================================================================
// Seed

#declare roleta = seed(342);

// ======================================================================
// DESCRI��O DA CENA 

#macro arvore(P, A, K)

  #local k = K;

  #local chance = rand(roleta);

  #if (k = 0 )
    sphere{ P, A*1.05
    texture{tx_espelho}
  }

  #else
    #local r2 = <P.x, P.y, P.z + (6*A)>;

    #local raio2 = A*0.7;

    union{
      cone{<0, 0, 0>, A , r2, raio2
      translate P
      texture{tx_fosca}
      }

      sphere{  <0,0,0>, raio2
      translate r2
      translate P
      texture{tx_fosca}
      }

      #if(chance <= 0.9 )
        object{arvore(<0,0,0>, raio2, k-1)
        rotate <-cos(k*chance*23)*30,sin(k*chance*40)*30,-sin(k*chance)*10>
        translate r2
        translate P
      }
      #end

      object{arvore(<0,0,0>, raio2, k-1) 
      rotate <sin(k*chance*30)*30, cos(k*chance*30)*30, sin(k*(1-chance))*10> 
      translate r2
      translate P}
    }
  #end
#end

#macro plantacao(N, A, K)
  #local n = N;
  #union{
  #while(n>0)
      #local P = <sin(rand(roleta)*50)*10,cos(rand(roleta)*50)*10,0>;
      object{arvore(<0, 0, 0>, A, K) translate P}
      #local n = n-1;
  #end
  }

#end

union{
  object{plantacao(10, 0.2, 10)}
}


#include "camlight.inc"
#declare centro_cena = < -2, 2, 0 >;
#declare raio_cena = 10;
#declare dir_camera = < 40, -40, 10 >;
#declare dist_camera = 50*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)