// 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_vermelha =
  texture{
    pigment{ color rgb < 1.00, 0, 0 > }
}

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

#declare tx_verde =
  texture{
    pigment{ color rgb < 0, 1, 0 > }
  }

#declare tx_azul =
  texture{
    pigment{ color rgb < 0, 0, 1.00 > }
  }

#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.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#macro interpola4(t0, a0, a1, a2, a3, t3, tt)
        #local a01 = interpola(t0, a0, t3, a1, tt);
        #local a12 = interpola(t0, a1, t3, a2, tt);
        #local a23 = interpola(t0, a2, t3, a3, tt);
        #local a012 = interpola(t0, a01, t3, a12, tt);
        #local a123 = interpola(t0, a12, t3, a23, tt);
        #local a01234 = interpola(t0, a012, t3, a123, tt);
        (a01234)
#end

#macro grafico(x0, y0, y1, y2, y3, x3, n,tt)
                #local yy = interpola4(x0, y0, y1, y2, y3, x3, tt);
                sphere { yy, 0.51 }
#end

#macro grafico4(x0, g1, g2, h1, h2, i1, i2, j1, j2, x3, n,tt)
        #local g3 = (g2 + h1)/2;
        #local h0 = g3;
        #local h3 = (h2 + i1)/2;
        #local i0 = h3;
        #local i3 = (i2 + j1)/2;
        #local j0 = i3;

        #local j3 = (g1+j2)/2;
        #local g0 = j3;

        #local dist = (x3-x0)/4;
        #if(tt < 0.25)
        grafico(0, g0, g1, g2, g3, 0.25, n,tt)
        #else
        #if(tt < 0.5)
        grafico(0.25, h0, h1, h2, h3, 0.5, n,tt)
        #else
        #if(tt < 0.75)
        grafico(0.5, i0, i1, i2, i3, 0.75, n,tt)
        #else
        #if(tt < x3)
        grafico(0.75, j0, j1, j2, j3, 1, n,tt)
        #end
        #end
        #end
        #end
#end

#macro interpola(f0, v0, f1, v1, f)
        #local ss = (f-f0)/(f1-f0);
        #local rr = 1 - ss;
        (rr*v0+ss*v1)
#end

#include "retalho.inc"
#include "eixos.inc"

#macro retalho3(j1,j2,j3,j4,j5,j6,j7,j8,j9,j10,j11,j12, k5, k6, k7, k8, k9, k10, k11, k12, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, rad,txg1,txr1, txg2, txr2, txg3, txr3)
        #local j13 = (j9+k5)/2;
        #local k1 = j13;
        #local j14 = (j10+k6)/2;
        #local k2 = j14;
        #local j15 = (j11+k7)/2;
        #local k3 = j15;
        #local j16 = (j12+k8)/2;
        #local k4 = j16;
        #local k13 = (k9+l5)/2;
        #local l1 = k13;
        #local k14 = (k10+l6)/2;
        #local l2 = k14;
        #local k15 = (k11+l7)/2;
        #local l3 = k15;
        #local k16 = (k12+l8)/2;
        #local l4 = k14;

        retalho(j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15, j16, rad, txg1, txr1)
        retalho(k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, k11, k12, k13, k14, k15, k16, rad, txg2, txr2)
        retalho(l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, l11, l12, l13, l14, l15, l16, rad, txg3, txr3)
#end

#macro graficox(x0, y0, y1, y2, y3, x3, n)
        #local delta = (x3-x0)/n;
        #local i = 0;
        #local xx = x0;
        union {
        #while (i <= n)
                #local yy = interpola4(x0, y0, y1, y2, y3, x3, xx);
                sphere { yy, 0.31 }
                #local xx = xx + delta;
                #local i = i + 1;
        #end
        }
#end

#macro graficox4(x0, g1, g2, h1, h2, i1, i2, j1, j2, x3, n)
        #local g3 = (g2 + h1)/2;
        #local h0 = g3;
        #local h3 = (h2 + i1)/2;
        #local i0 = h3;
        #local i3 = (i2 + j1)/2;
        #local j0 = i3;

        #local j3 = (g1+j2)/2;
        #local g0 = j3;

        #local dist = (x3-x0)/4;
        union {
        graficox(x0, g0, g1, g2, g3, x0+dist, n)
        graficox(x0+dist, h0, h1, h2, h3, x0+2*dist, n)
        graficox(x0+2*dist, i0, i1, i2, i3, x0+3*dist, n)
        graficox(x0+3*dist, j0, j1, j2, j3, x0+4*dist, n)
        }
#end

union {
        object {grafico4(0, <2,-5,1>, <-4,5,7> , <-1, 4,-5>,<2,4, -3>, <5,4,4>, <3,-5,1>, <1,-2,4>,<3,1,-3>, 1, 100, clock) texture{tx_azul} translate <-2, 0, 0>}
        object {graficox4(0, <2,-5,1>, <-4,5,7> , <-1, 4,-5>,<2,4, -3>, <5,4,4>, <3,-5,1>, <1,-2,4>,<3,1,-3>, 1, 30) texture{tx_fosca} translate <-2, 0, 0>}

        retalho3(<0,0,0>,<0,1,0>,<0,2,0>,<0,3,0>,<1,0,3>,<1,1,3>,<1,2,3>,<1,3,3>,<2,0,-1>,<2,1,-1>,<2,2,-1>,<2,3,-1>, <7,0,-3>,<7,1,-3>,<7,2,-3>,<7,3,-3>,<10,0,1>,<10,1,1>,<10,2,1>,<10,3,1>,
<6,0,2>, <6,1,2>, <6,2,2>, <6,3,2>, <1,0,4>, <1,1,4>, <1,2,4>, <1,3,4>, <14,0,7>,<14,1,7>,<14,2,7>,<14,3,7>,0.0001, tx_vidro, tx_verde, tx_vidro, tx_azul, tx_vidro, tx_fosca)
}

#include "camlight.inc"
#declare centro_cena = < 2.00, 3.00, 2.00 >;
#declare raio_cena = 16.0;
#declare dir_camera = < 14.00, -60.00, 2.00 >;
#declare dist_camera = 60.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)