help needed

I have this code that is part of a program that makes a 3d piont circle around a square box. I was asked to put a “tail” on the point so that it looks loike a “comet”. I have been sort of unable to do it properly and I was wondering if you could give me a hand.

The idea is that I modify the draw_model function. The tail consist of a line that connects the actual position of the point with the last “tail_size” positions that have been used (tail_size is a constant defined by me).

I had thought of using something like:

glBegin(GL_LINE_STRIP);

for (?; ?; ?)
{
x = …
y = …
z = …
glColor3d(r, g, b);
glVertex3d(x, y, z);
}

glEnd();

Starting from the initial position the tail should start from red (r=1.0, g=0.0, b=0.0) and gradualy turn to black (r=0.0, g=0.0, g=0.0) when it reaches the last point.

The following is the .c file in charge of the process. (there are other files that are needed to compile the final program, but I asume you wouldn’t need them).

Here is the .c :

#endif

#if defined(WIN32) | | defined(CYGWIN32)
/* OpenGL needs this to be included before gl.h. */
#include <windows.h>
#endif

#include <GL/gl.h>

#include <model.h>
#include <setup.h>

/* models variables. */
static double t = 0.0;
static double dt = 0.2;

/* Makes time advance in the model. */
void
time_step(void)
{
t += dt;
}

/* t scale from [0, period] to [0, 1]. */
static double
t_to_01(double t, double period)
{
return (t - floor(t/period)*period)/period;
}

void
draw_model(void)
{
static double x;
static double y;
static double z;
static double last_t = -1.0;

static const double r_period = 1000.0;
static const double theta_period = 100.0;
const double r = 0.4*(vv_xmax - vv_xmin);

#if defined(DEBUG)
fprintf(stderr, "draw_model t = %f.
", t);
#endif

if (t != last_t)
{
double theta = 2 * M_PI * t_to_01(t, theta_period);

  x = r*sin(theta);
  y = r*cos(theta);
  z = 2*r*t_to_01(t, r_period) - r;
}

glBegin(GL_POINTS);
glColor3d(1.0, 0.7, 0.7);
glVertex3d(x, y, z);
glEnd();
}