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

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 < 1.00, 0.80, 0.10 > }
    finish{ diffuse 0.9 ambient 0.1 }
  }

#declare tx_peca =
  texture{
    pigment{ color rgb < 0.5, 0.5, 0.5 > }
    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 }
  }

#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_xadrez =
  texture{
    pigment{ checker color rgb < 0.0, 0.0, 0.0 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 1.0
  }

#include "eixos.inc"
#include "retalho-simples.inc"

#declare V = 4;
#declare H = 4;

#declare p = array[4][4];
#declare P = array[V][H][4][4];

#declare P[0][0][0][0] = <1,1,0>;
#declare P[0][0][0][1] = <1,2,0>;
#declare P[0][0][0][2] = <1,3,0>;
#declare P[0][0][0][3] = <1,4,0>;
#declare P[0][0][1][0] = <3,1,2>;
#declare P[0][0][1][1] = <3,2,2>;
#declare P[0][0][1][2] = <3,3,2>;
#declare P[0][0][1][3] = <3,4,2>;
#declare P[0][0][2][0] = <5,1,0>;
#declare P[0][0][2][1] = <5,2,0>;
#declare P[0][0][2][2] = <5,3,0>;
#declare P[0][0][2][3] = <5,4,0>;
#declare P[0][0][3][0] = <7,1,0>;
#declare P[0][0][3][1] = <7,2,0>;
#declare P[0][0][3][2] = <7,3,0>;
#declare P[0][0][3][3] = <7,4,0>;

#for(i, 0, V-1, 1)
  #for(j, 0, H-1, 1)
    #for(k, 0, 3, 1)
      #for(l, 0, 3, 1)
        #declare P[i][j][k][l] = <i+j+k+l, i*j*k+l, l + i>;
      #end
    #end
  #end
#end

#macro carro(P)
        #for(i, 0, V-1, 1)
          #for(j, 0, H-1, 1)
            #for(k, 0, 3, 1)
              #for(l, 0, 3, 1)
                #declare p[k][l] = P[i][j][k][l];
              #end
            #end
            object{retalho(p,0.01,tx_peca,tx_fosca)}
          #end
        #end
#end

#macro emenda_retalho(P, r0, s0, r1, s1)
        #for(i, 0, 3, 1)
                #declare P[r0][s0][i][3] = (P[r0][s0][i][2] + P[r1][s1][i][1])/2;
                #declare P[r1][s1][i][0] = P[r0][s0][i][3];
        #end
        #for(i, 0, 3, 1)
                #declare P[r0][s0][3][i] = (P[r0][s0][2][i] + P[r1][s1][1][i])/2;
                #declare P[r1][s1][0][i] = P[r0][s0][3][i];
        #end
#end

#for(i, 0, V-1, 1)
  #for(j, 0, H-2, 1)
    emenda_retalho(P, i, j, i, j+1)
  #end
#end

#for(i, 0, V-2, 1)
  #for(j, 0, H-1, 1)
    emenda_retalho(P, i, j, i+1, j)
  #end
#end

carro(P)

#include "camlight.inc"
#declare centro_cena = < 0, 2, 8 >;
#declare raio_cena = 15;
#declare dir_camera = < -10.00, -30.00, 20.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)