
#include<GL/glut.h>
#include<cmath>
float angle=0.0;
float a=0.0;
static int isAnimate = 0; 
static int isa= 0; 
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0);

}

void draw(float x,float y,float r)
{
	int N = 360;
	float Dtheta = 2 * 3.1415926 / N;
	float angle = 0.0;
	glBegin(GL_TRIANGLE_FAN);
	glColor3f(0, 1, 0);
	for (int i = 0; i <= N; i++)
	{
		float angle = i*Dtheta;
				glVertex2f(x+r*cos(angle) ,y+r*sin(angle));
		}
		glEnd();
		}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();

glTranslatef(0.0, 0.0, -15.0);
draw(0.0,0.0,2.0);
glPopMatrix();
glPushMatrix();
glTranslatef(0.0, 0.0, -15.0);
glTranslatef(2.0,0.0,0.0);


glRotatef(a,0.0,1.0,0.0);
//glRotatef(angle,0.0,1.0,0.0);
glTranslatef(-2.0,0.0,0.0);
draw(5.0,0.0,1.0);
glPopMatrix();
glFlush();
}

void resize(int w,int h)
{
glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();


//glOrtho(-10.0,10.0,-10.0,10.0,-1.0,1.0);
 glFrustum(-5.0, 5.0, -5.0, 5.0, 5.0, 100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

void increaseAngle(void)
{
   angle += 0.5;
   
   if (angle > 360.0) angle -= 360.0;
   glutPostRedisplay();
}
void increasea(void)
{
   
   a+=0.5;
   if (a > 360.0) a -= 360.0;
   glutPostRedisplay();
}

void keyInput(unsigned char key, int x, int y)
{
   switch(key) 
   {      case 27:
         exit(0);
         break;
      case ' ':
         if(isAnimate) 
		 {
            isAnimate = 0;
	  glutIdleFunc(NULL);
		 }
		 else 
		 {
            isAnimate = 1;
		    glutIdleFunc(increaseAngle);
		 }
		 case 'c':
		 	if(isa){
		 	isa=0;
		 	glutIdleFunc(NULL);
		 }
		 else{
		 isa=1;
		 	glutIdleFunc(increasea);}
         break;
      default:
         break;
   }
}

 int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (250, 250);
glutInitWindowPosition (100, 100);
glutCreateWindow ("hello");
init ();
glutDisplayFunc(display);
glutReshapeFunc(resize);
glutKeyboardFunc( keyInput);
glutMainLoop();
return 0; 
}
