#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>
#include <unistd.h>

void init();
void display();

int main(int argc, char** argv)
{
  // Call GLUT set up functions
  glutInit(&argc, argv);
  glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);

  // Set the window size and position
  glutInitWindowSize (250, 250); 
  glutInitWindowPosition (100, 100);

  // The name of the window
  glutCreateWindow ("hello");

  // Call our custom defined init function
  init ();

  // Call our custom defined display function
  glutDisplayFunc(display); 

  // Start showing the graphics
  glutMainLoop();
  return 0;
}

void init (void) 
{
  // Clear to black
  glClearColor (0.0, 0.0, 0.0, 0.0);

  // GL matrix loading
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();

  // Our viewing window coordinates will be from (0,0) to (1,1)
  glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
}


void display()
{
  // Clear the background
  glClear (GL_COLOR_BUFFER_BIT);

  // Set the line width to 3
  glLineWidth(3);

  // Draw a red circle by drawing a bunch of triangles
  glColor3f(1, 0, 0);
  glBegin(GL_TRIANGLES);

  double radius = 0.1;
  double x_center = .7;
  double y_center = .7;

  double vectorY1=y_center;
  double vectorX1=x_center;


  for(int i=0;i<=360;i++)
    {
      double angle = i/57.3;
      double vectorX = x_center + (radius * sin(angle));
      double vectorY = y_center + (radius * cos(angle));

      glVertex2d(x_center, y_center);
      glVertex2d(vectorX1,vectorY1);
      glVertex2d(vectorX,vectorY);

      vectorY1=vectorY;
      vectorX1=vectorX;
    }

  glEnd();
  glFlush ();


  // Wait 5 seconds
  usleep(5*1000000);

  // Draw some green lines
  glColor3f(0, 1, 0);
  glBegin(GL_LINES);
  glVertex2f(.2, .2);
  glVertex2f(.6, .2);
  glEnd();

  // Flush the buffer
  glFlush ();
}

