#include <GLUT/glut.h>
#include <OpenGL/gl.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>

#define SEED 31415926
#define MAX_V 10000
#define DIV_V 5000.0
#define SUB_V 1

void renderer(void);
void initialSetup(void);
void changeSize(GLsizei w, GLsizei h);
void tf(int blah);

GLfloat xs [256], dxs[256], ys[256], dys[256], zs [256], dzs [256];

int main (int argc, const char * argv[]) 
{
    glutInit(&argc, (char **)argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutCreateWindow("Cool Demo");
    glutDisplayFunc(renderer);
    glutReshapeFunc(changeSize);
    initialSetup();
    glutTimerFunc(25, tf, 1);
    glutMainLoop();
    return 0;
}

void renderer()
{
    int i;
    
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    glColor3f(1,0,0);
    glBegin(GL_POINTS);
   
    for(i=0; i < 256; i++)
    {    
        glVertex3f(xs[i], ys[i], zs[i]);
        xs[i] += dxs[i];
        ys[i] += dys[i];
        zs[i] += dzs[i];
    }
    
    glEnd();
    glPopMatrix();
    glutSwapBuffers();
}

void tf(int blah)
{
    glutPostRedisplay();
    glutTimerFunc(25, tf, 1);
}

void changeSize(GLsizei w, GLsizei h)
{
    GLfloat sideRange = 200;
    
    glViewport(0,0,w,h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-sideRange, sideRange, -sideRange, sideRange, sideRange, -sideRange);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
}


void initialSetup(void)
{
    int i;
    
    glClearColor(0.0, 0.0, 0.0, 1.0);
    
    srand(SEED);
    
    for(i=0; i < 256; i++)
    {
        xs[i] = ys[i] = zs[i] = 0;
        dxs[i] = (rand() % MAX_V) / DIV_V - SUB_V;
        dys[i] = (rand() % MAX_V) / DIV_V - SUB_V;
        dzs[i] = (rand() % MAX_V) / DIV_V - SUB_V;
    }
    
}