// 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_branca =
  texture{
    pigment{ color rgb < 2, 2, 2> }
  }

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

#declare tx_madeira =
  texture{
    pigment{ color rgb < 0.80, 0.55, 0.40 > }
    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.10, 0.32, 0.60 >, color rgb < 1.00, 0.97, 0.90 > }
    finish{ diffuse 0.9 ambient 0.1 }
    scale 2.0
  }

#declare tx_hyperglass =
        texture {
                pigment { color rgb < 0.90 , 0.15 , 0.15 > filter 0.28 }
                finish { diffuse 0.33 ambient 0.55 }
        }

#declare chao = box { <-40,-40,-1> , <20,20,0> }

#include "eixos.inc"

#declare pingo_r = 0.1;

#declare pingo =
sphere {
        <0,0,0> , pingo_r
}

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

        (rr*v0+ss*v1)
#end

#macro quatro_graficos(x0,y0,c1y1,c1y2,c2y1,c2y2,c3y1,c3y2,c4y1,c4y2,c4y3,xfim)
   #local c2y0 = (c2y1+c1y2)/2;
   #local c1y3=c2y0;
   #local c3y0 = (c3y1+c2y2)/2;
   #local c2y3=c3y0;
   #local c4y0 = (c4y1+c3y2)/2;
   #local c3y3=c4y0;

   #local dist = (xfim-x0)/4;

union {
    grafico(x0,(y0+c4y3)/2,c1y1,c1y2,c1y3,x0+dist,nbolinhas)
    grafico(x0+dist,c2y0,c2y1,c2y2,c2y3,x0+dist*2,nbolinhas)
    grafico(x0+dist*2,c3y0,c3y1,c3y2,c3y3,x0+dist*3,nbolinhas)
    grafico(x0+dist*3,c4y0,c4y1,c4y2,(y0+c4y3)/2,x0+dist*4,nbolinhas)
}
#end

#macro quatro_graficos_2(x0,y0,c1y1,c1y2,c2y1,c2y2,c3y1,c3y2,c4y1,c4y2,c4y3,xfim)
   #local c2y0 = (c2y1+c1y2)/2;
   #local c1y3=c2y0;
   #local c3y0 = (c3y1+c2y2)/2;
   #local c2y3=c3y0;
   #local c4y0 = (c4y1+c3y2)/2;
   #local c3y3=c4y0;
   #local time = clock;

   #local dist = (xfim-x0)/4;

union {
        #if (time < 0.25)
            bolinhas(x0,(y0+c4y3)/2,c1y1,c1y2,c1y3,x0+dist,nbolinhas,time)
        #else
                #if (time >= 0.25 & time < 0.50)
                    bolinhas(x0+dist,c2y0,c2y1,c2y2,c2y3,x0+dist*2,nbolinhas,time-0.25)
                #else
                        #if (time >= 0.50 & time < 0.75)
                            bolinhas(x0+dist*2,c3y0,c3y1,c3y2,c3y3,x0+dist*3,nbolinhas,time-0.50)
                        #else
                            bolinhas(x0+dist*3,c4y0,c4y1,c4y2,(y0+c4y3)/2,x0+dist*4,nbolinhas,time-0.75)
                        #end
                #end
        #end
}
#end

#macro interpola4(t0,v0,v1,v2,v3,t3,tt)
        #local v01 = interpola(t0,v0,t3,v1,tt);
        #local v12 = interpola(t0,v1,t3,v2,tt);
        #local v23 = interpola(t0,v2,t3,v3,tt);

        interpola(t0,interpola(t0,v01,t3,v12,tt),t3,interpola(t0,v12,t3,v23,tt),tt);
#end

#macro grafico(x0,y0,y1,y2,y3,x3,n)
        #local i = 0;
        #local delta = (x3-x0)/n;
        #local xx = x0;

        union {
                #while (i < n)
                        #local yy = interpola4(x0,y0,y1,y2,y3,x3,xx);
                        union {
                        object { pingo translate yy }
                        }
                        #local i = i+1;
                        #local xx = xx + delta;
                #end
        }
#end

#macro bolinhas(x0,y0,y1,y2,y3,x3,n,time)
        #local time = 4*time;
        union {
                #local delta = (x3-x0)/n;

                #local xx = x0*(1-time) + time*((n-1)*(delta)+x0);

                #local yy = interpola4(x0,y0,y1,y2,y3,x3,xx);
                union {
                        object { pingo scale 2 }
                        translate yy
                }
        }
#end

#macro tresretalhos()
        #local p0m = (p03[0] + p13[0])/2;
        #local p1m = (p03[1] + p13[1])/2;
        #local p2m = (p03[2] + p13[2])/2;
        #local p3m = (p03[3] + p13[3])/2;
        #local p20m = (p12[0] + p23[0])/2;
        #local p21m = (p12[1] + p23[1])/2;
        #local p22m = (p12[2] + p23[2])/2;
        #local p23m = (p12[3] + p23[3])/2;
union {
        object { retalho(p01[0],p01[1],p01[2],p01[3],p02[0],p02[1],p02[2],p02[3],p03[0],p03[1],p03[2]p03[3],p0m,p1m,p2m,p3m,radiusomg,tx_fosca,tx_plastico) }
        object { retalho(p0m,p1m,p2m,p3m,p12[0],p12[1],p12[2],p12[3],p13[0],p13[1],p13[2],p13[3],p20m,p21m,p22m,p23m,radiusomg,tx_fosca,tx_plastico) }
        object { retalho(p20m,p21m,p22m,p23m,p21[0],p21[1],p21[2],p21[3],p22[0],p22[1],p22[2],p22[3],p23[0],p23[1],p23[2],p23[3],radiusomg,tx_fosca,tx_plastico) }

}
#end

#declare nbolinhas = 300;
#declare curva = array[10] {<1,2,2>,<0,3,1>,<1,10,1>,<1,3,2>,<0,5,6>,<3,5,6>,<3,5,0>,<2,4,1>,<1,1,1>,<3,-1,2>}
#declare p01 = array[4] { <0,0,0> , <-1,0,0>, <-2,0,0> , <-3,0,0>}
#declare p02 = array[4] { <0,1,0> , <-1,1,0> , <-2,1,0>, <-3,1,0> }
#declare p03 = array[4] { <0,2,2> , <-1,2,2> , <-2,2,2>, <-3,2,2> }

#declare p12 = array[4] { <0,4,0> , <-1,4,0>, <-2,4,0> , <-3,4,0>}
#declare p13 = array[4] { <0,5,0> , <-1,5,-1> , <-2,5,-1>, <-3,5,0> }

#declare p21 = array[4] { <0,7,0> , <-1,7,0>, <-2,7,0> , <-3,7,0>}
#declare p22 = array[4] { <0,8,0> , <-1,8,0> , <-2,8,0>, <-3,8,0> }
#declare p23 = array[4] { <0,9,0> , <-1,9,0> , <-2,9,0>, <-3,9,0> }

#declare tempo = array[2] {0,16}
#declare radiusomg = 0.05;

#include "retalho.inc"

union {
        union {
                union {
                        eixos(3.00)
                        object { quatro_graficos(tempo[0],curva[0],curva[1],curva[2],curva[3],curva[4],curva[5],curva[6],curva[7],curva[8],curva[9],tempo[1]) texture{ tx_plastico }  }

                        object { quatro_graficos_2(tempo[0],curva[0],curva[1],curva[2],curva[3],curva[4],curva[5],curva[6],curva[7],curva[8],curva[9],tempo[1]) texture{ tx_fosca }  }
                }
                rotate<-2,0,41>
                translate<0,-8,0>
        }

}

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