#include "epix2.h"
using namespace ePiX2;

Point torus(double u, double v)
{
  double r(0.5), R(1.+r*Cos(u));
  return Point(R*Cos(v), R*Sin(v), r*Sin(u));
}

Point f(double t)
{
  return torus(t/60.0, t/140.0);
  //return Point(Sin(0.02*M_PI*t), Sin(0.03*M_PI*t), Cos(0.01*M_PI*t));
}

Point g(double t)
{
  return torus(0.0625+t/60.0, t/140.0);
  //return Point(Sin(0.02*M_PI*t), Sin(0.03*M_PI*t), Cos(0.01*M_PI*t));
}

int main() {

  World world;

  Camera camera;
  Picture picture(Pair(-2,-2), Pair(2,2), "6x6in");

  Color back_color(Black()); //RGB(1,1,0.8));

  picture.backing(back_color);

  Duo_Pen halo(bold(Red()), Pen(back_color, "4pt"));

  world << Circle().stroke(bbold(Yellow()));
  rotations();

  for (int i=0; i<420; ++i)
    world << Segment(f(i), f(i+1)).stroke(halo)
	  << Segment(g(i), g(i+1)).stroke(halo)
	  << Segment(f(i), g(i-2)).stroke(plain(Yellow()));

  //  world.fog(Black(), 0.75,6);

  camera.at(Point(1.5, 6.5, 3));
  world.flash(picture, camera);

  picture.crop();

  print(picture, "knots3.eepic", PSTricks());
}
