background{ color rgb <0.53, 0.81, 0.92> }

#declare comp_toco_aresta = 0.5;
#declare raio_aresta = 0.25;

#declare tx_bug =
  texture {
    pigment { color rgb <1.000, 0.000, 0.700> }
    finish { diffuse 0.5 ambient 0.5 }
  }

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

#declare tx_aresta =
  texture {
    pigment { color rgb 4*<0.2, 0.2, 0.2> }
    finish { diffuse 0.7 ambient 0.1 metallic reflection 0.05 }
  }

#macro vert_k1(xx, yy)
  #local vert =
    union {
      // vertice
      sphere {
        <xx, yy, 0>, 1
        texture { tx_vert }
      }

      // arestas
      cylinder {
        <xx, yy, 0>, <xx, yy + 1 + comp_toco_aresta, 0>, raio_aresta
        texture { tx_aresta }
      }

    }
  
  vert
#end

#macro vert_k2(xx, yy)
  #local vert =
    union {
      // vertice
      union {
        sphere {
          <xx, yy, 0>, 1
        }

        cone {
          <xx, yy, 0>, 1.0
          <xx, yy, 2>, 0
        }
        
        texture { tx_vert }
      }

      // arestas
      union {
        cylinder {
          <xx, yy, 0>, <xx, yy + 1 + comp_toco_aresta, 0>, raio_aresta
        }
        
        cylinder {
          <xx, yy, 0>, <xx, yy - 1 - comp_toco_aresta, 0>, raio_aresta
        }

        texture { tx_aresta }
      }

    }
  
  vert
#end

#macro vert_k3(xx, yy)
    #local vert =
    union {
      // vertice
      union {
        cone {
          <xx, yy, 0>, 1.0
          <xx, yy, 2>, 0
        }

        cone {
          <xx, yy, 0>, 1.0
          <xx, yy, -2>, 0
        }
        
        texture { tx_vert }
      }

      // arestas
      union {
        cylinder {
          <xx, yy, 0>, <xx + sqrt(2 * (1 + comp_toco_aresta)), yy + sqrt(2 * (1 + comp_toco_aresta)), 0>, raio_aresta
        }
        
        cylinder {
          <xx, yy, 0>, <xx - sqrt(2 * (1 + comp_toco_aresta)), yy + sqrt(2 * (1 + comp_toco_aresta)), 0>, raio_aresta
        }

        cylinder {
          <xx, yy, 0>, <xx, yy - 1 - comp_toco_aresta, 0>, raio_aresta
        }

        texture { tx_aresta }
      }

    }
  
  vert
#end

#macro vert_k4(xx, yy)
    #local vert =
    union {
      // vertice
      union {
        box {
          <xx - 1, yy - 1, 0>,
          <xx + 1, yy + 1, 1>
        }

        sphere {
          <xx, yy, 1>, 1.0
        }
        
        texture { tx_vert }
      }

      // arestas
      union {
        cylinder {
          <xx, yy, 0.5>, <xx + 1 + comp_toco_aresta, yy, 0.5>, raio_aresta
        }
        
        cylinder {
          <xx, yy, 0.5>, <xx, yy + 1 + comp_toco_aresta, 0.5>, raio_aresta
        }

        cylinder {
          <xx, yy, 0.5>, <xx - (1 + comp_toco_aresta), yy, 0.5>, raio_aresta
        }

        cylinder {
          <xx, yy, 0.5>, <xx, yy - (1 + comp_toco_aresta), 0.5>, raio_aresta
        }

        texture { tx_aresta }
      }

    }
  
  vert
#end

#macro interpola1(tt, t0, v0, t1, v1)
  #local ss = (tt - t0)/(t1 - t0);
  #local vv = (1 - ss) * v0 + ss * v1;
  vv
#end

// interpolacao curva de bezier 3 grau
#macro interpola3(tt, ta, tb, v0, v1, v2, v3)
  #local v01 = interpola1(tt, ta, v0, tb, v1);
  #local v12 = interpola1(tt, ta, v1, tb, v2);
  #local v23 = interpola1(tt, ta, v2, tb, v3);
  #local v012 = interpola1(tt, ta, v01, tb, v12);
  #local v123 = interpola1(tt, ta, v12, tb, v23);

  #local v0123 = interpola1(tt, ta, v012, tb, v123);
  v0123
#end

#macro bezier(v0, v1, v2, v3)
  #local a = 0;
  #local b = 10;
  #local cur_step = a;

  union {
    #while (cur_step <= b)
      #local p = interpola3(cur_step, a, b, v0, v1, v2, v3);
      sphere { p, 0.05 texture{ tx_bug } }

      #local cur_step = cur_step + 0.01;
    #end
  }
#end

#local bp0 = <0, 0, 0>;
#local bp1 = <1, 2, 0>;
#local bp2 = <2, -8, 0>;
#local bp3 = <3, 3, 0>;

#include "bezpoly.inc"
union{
  object { bezier(bp0, bp1, bp2, bp3) }
  object { bezpoly(bp0, bp1, bp2, bp3, 0.1) }
  rotate 90*z translate 0.5*z
}

object { vert_k1(0, -3) }
object { vert_k2(3, -3) }
object { vert_k3(7, -3) }
object { vert_k4(-3, -3) }

#include "eixos.inc"
//object{ eixos(10) }

#declare cmin = <  -4, -6, -2.5 >;
#declare cmax = <  +9, +4, +2.0 >;

box{ cmin-<2,2,0> <cmax.x,cmax.y,cmin.z>+<2,2,0.01>  texture{ pigment{ color rgb 0.9*<1,1,1> } finish {diffuse 0.7 ambient 0.3 } } }

#include "camlight.inc"
#declare centro_cena = (cmin + cmax)/2;
#declare raio_cena = 0.5*vlength(cmin - cmax);
#declare dir_camera = < 3.10, 2.00, 2.00 >;
#declare dist_camera = 5*raio_cena;
#declare intens_luz = 1.20;
camlight(centro_cena, raio_cena, dir_camera, dist_camera , z, intens_luz)