// 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_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_vermelho =
  texture{
    pigment{ color rgb < 1.00, 0, 0 > }
    finish{ diffuse 0.2 reflection 0.7*< 1.00, 0.85, 0.30 > ambient 0.1 }
  }

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

#declare raio = 1.000;
#include "eixos.inc"

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

  (rr*v0 +ss*v1)
#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);

#local v012 = interpola(t0,v01,t3,v12,tt);
#local v123 = interpola(t0,v12,t3,v23,tt);

interpola(t0,v012,t3,v123,tt);
#end

#macro grafico(x0,y0,y1,y2,y3,x3,tt)

        #local yy1 = interpola4(x0,y0,y1,y2,y3,x3,tt);
        #local yy2 = interpola4(x0,y0,y1,y2,y3,x3,tt+0.01);
        #local yy3 = interpola4(x0,y0,y1,y2,y3,x3,tt+0.02);
        #local yy4 = interpola4(x0,y0,y1,y2,y3,x3,tt+0.03);

object{ sphere { yy1, 0.30 } texture { tx_vermelho } translate <-3,0,2.5>}
object{ sphere { yy2, 0.30 } texture { tx_vermelho } translate <-3,0,2.5>}
object{ sphere { yy3, 0.30 } texture { tx_vermelho } translate <-3,0,2.5>}
object{ sphere { yy4, 0.30 } texture { tx_vermelho } translate <-3,0,2.5>}

#end

#macro grafico2(x0,y0,y1,y2,y3,x3,N)
 #local delta = (x3-x0)/N;
 #local i = 0;
 #local xx = x0;
 #while(i <= N)
   #local yy = interpola4(x0,y0,y1,y2,y3,x3,xx);
   object{ sphere { yy, 0.10 } texture { tx_plastico } translate <-3,0,2.5>}
   #local xx = xx + delta;
   #local i = i + 1;
 #end
#end

#macro grafico5(x0,y1,y2,h1,h2,u1,u2,p1,p2,x1,n)
   #local h0 = (h1+y2)/2;
   #local y3=h0;
   #local u0 = (u1+h2)/2;
   #local h3=u0;
   #local p0 = (p1+u2)/2;
   #local u3=p0;

   #local y0 = (y1+p2)/2;
   #local p3 = y0;

   #local k = (x1-x0)/4;

        grafico2(x0,y0,y1,y2,y3,x0+k,n)
        grafico2(x0+k,h0,h1,h2,h3,x0+k*2,n)
        grafico2(x0+k*2,u0,u1,u2,u3,x0+k*3,n)
        grafico2(x0+k*3,p0,p1,p2,p3,x0+k*4,n)

#end

#macro grafico4(x0,y1,y2,h1,h2,u1,u2,p1,p2,x1,n,tt)
   #local h0 = (h1+y2)/2;
   #local y3=h0;
   #local u0 = (u1+h2)/2;
   #local h3=u0;
   #local p0 = (p1+u2)/2;
   #local u3=p0;

   #local y0 = (y1+p2)/2;
   #local p3 = y0;

   #local k = (x1-x0)/4;
        #if(tt<k)
        grafico(x0,y0,y1,y2,y3,x0+k,tt)
        #else
        #if(tt<2*k)
        grafico(x0+k,h0,h1,h2,h3,x0+k*2,tt)
        #else
        #if(tt<3*k)
        grafico(x0+k*2,u0,u1,u2,u3,x0+k*3,tt)
        #else
        #if(tt<4*k)
        grafico(x0+k*3,p0,p1,p2,p3,x0+k*4,tt)
        #end
        #end
        #end
        #end

#end
#include "retalho.inc"

#macro ret(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20,p25,p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36,r,tx1,tx2,tx3,tx4,tx5,tx6)

        #local pp1 = (p9+p13)/2;
        #local pp2 = (p10+p14)/2;
        #local pp3 = (p11+p15)/2;
        #local pp4 = (p12+p16)/2;
        #local ppp1 = (p17+p25)/2;
        #local ppp2 = (p18+p26)/2;
        #local ppp3 = (p19+p27)/2;
        #local ppp4 = (p20+p28)/2;

   retalho(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,pp1,pp2,pp3,pp4,r,tx1,tx2)
   retalho(pp1,pp2,pp3,pp4,p13,p14,p15,p16,p17,p18,p19,p20,ppp1,ppp2,ppp3,ppp4,r,tx3,tx4)
   retalho(ppp1,ppp2,ppp3,ppp4,p25,p26,p27,p28,p29,p30,p31,p32,p33,p34,p35,p36,r,tx5,tx6)

#end
union {
object{ eixos(3.00) }
grafico4(0,<3,-2,5>,<5,3,1>,<1,-5,-4>,<-4,1,4>,<4,3,2>,<-4,-1,1>,<4,-3,2>,<-5,-4,1>,1,400,clock)
grafico5(0,<3,-2,5>,<5,3,1>,<1,-5,-4>,<-4,1,4>,<4,3,2>,<-4,-1,1>,<4,-3,2>,<-5,-4,1>,5,400)

}

#include "camlight.inc"
#declare centro_cena = < 1.00, 1.00, 1.00 >;
#declare raio_cena = 10.0;
#declare dir_camera = < 0.00, -2.00, 0 >;
#declare dist_camera = 80.0;
#declare intens_luz = 1.00;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)