// Last edited on 2019-07-17 06:01:56 by stolfilocal
// Processed by remove-cam-lights

background{ color rgb < 0.8, 0.7, 0.5 > }

#declare tx_corda =
    texture{
     pigment{ color rgb < 1.0, 0.6, 0.2 > }
     finish{ diffuse 0.9 ambient 0.1 }
}

#include "eixos.inc"

#macro interpola_linear(T,T0,T1,P0,P1)
  (P0+(T0+T/(T1-T0))*(P1-P0))
#end

#macro interpola_3d(T, T0, T1, P0, P00, P1, P11)
  (P0*pow((1-(T0+T/(T1-T0))),3) + P00*3*(T0+T/(T1-T0))*pow((1-(T0+T/(T1-T0))),2) + 3*P11*pow((T0+T/(T1-T0)),2)*(1-(T0+T/(T1-T0))) + pow((T0+T/(T1-T0)),3)*P1)
#end

#macro arco(A0, A1, A2, A3, T0, T1)
  union{
    #local T = T0;
    #while (T<=T1)
      object{ sphere {
        interpola_3d(T,T0,T1,A0, A1, A3, A2),
        0.2
        texture {tx_corda}}}
      #local T = T+1;
    #end
  }
#end

#macro make_no(P, N, M)
  union{
    #local I = 0;
    #while (I < N)
      arco(P[I][0],P[I][1],P[I][2],P[I][3],0,M)
      #local I = I + 1;
    #end
  }
#end

#macro matriz_no(P1, P2)

  #local P = array[3][4];
  #local PM = (P1+P2)/2;
  #local PM2 = (P1+PM)/2;

  #local P[0][0] = P1;
  #local P[0][1] = P1 + <8,1,3>;
  #local P[0][2] = PM + <-8,-1,3>;
  #local P[0][3] = PM;

  #local P[1][0] = PM;
  #local P[1][1] = PM - <-8,-1,3>;
  #local P[1][2] = PM2 + <0,0,1.5> + <0,7,0>;
  #local P[1][3] = PM2 + <0,0,1.5>;

  #local P[2][0] = P[1][3];
  #local P[2][1] = P[1][3] - <0,7,0>;
  #local P[2][2] = PM2 - <0,5,0>;
  #local P[2][3] = P2;

  P
#end

#macro matriz_no2(P1, P2)

  #local P = array[3][4];
  #local PM = (P1+P2)/2;
  #local PM2 = (P1+PM)/2;

  #local P[0][0] = P1;
  #local P[0][1] = P1 + <15,1,6>;
  #local P[0][2] = PM + <-15,-1,6>;
  #local P[0][3] = PM;

  #local P[1][0] = PM;
  #local P[1][1] = PM - <-15,-1,6>;
  #local P[1][2] = PM2 + <0,0,1.5> + <-2,8,0>;
  #local P[1][3] = PM2 + <0,0,1.5>;

  #local P[2][0] = P[1][3];
  #local P[2][1] = P[1][3] - <-2,8,0>;
  #local P[2][2] = PM2 - <0,5,0>;
  #local P[2][3] = P2;

  P
#end

#macro interpola_linear_matriz(P,Q,N,C0,C1,CC)

  #declare R = array[N][4];

  #for (I,0,N-1,1)
    #for (J,0,3,1)
      #declare R[I][J] = <0,0,0>;
    #end
  #end

  #local I = 0;
  #while (I < N)
    #local K = 0;
    #while (K < 4)
        #declare R[I][K] = interpola_linear(CC,C0,C1,P[I][K],Q[I][K]);
        #local K = K + 1;
    #end
    #local I = I + 1;
  #end
  R
#end

union{

        #declare P = matriz_no2(<10,0,0>, <15,0,0>);
  #declare Q = matriz_no(<-12,0,0>, <-7,0,0>);
  object{ make_no(P, 3, 1000) translate 10*z }
  make_no(Q,3,1000)

  #local CC = 0;
  #while (CC < 5)
    #local R = interpola_linear_matriz(P,Q,3,0,5,CC);
    object{ make_no(R,3,1000) translate 30*(CC/5-0.5)*z }
    #local CC = CC + 1;
  #end
}

#include "camlight.inc"
#declare centro_cena = < 2.00, 0.00, -2.00 >;
#declare raio_cena = 25;

#declare dir_camera = < 0.0, -1.0, 1.0 >;
#declare dist_camera = 6*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)