




#include <iostream>
#include <cmath>
#include <GL/glut.h>
static int isAnimate = 0; 
int c=-1;
char ch;
using namespace std;




static int animationPeriod = 50; 
void animate(int value)
{
   if (isAnimate) 
   {
  
      glutPostRedisplay();     
      glutTimerFunc(animationPeriod, animate, 1);
   }
}
void keyInput(unsigned char key, int x, int y)
{
   switch(key) 
   {
      case 27:
         exit(0);
         break;
	  case ' ': 
         if (isAnimate) isAnimate = 0;
		 else 
		 {
	        isAnimate = 1; 
			animate(1);
		 }
		 break;
      default:
         break;
   }
}

void specialKeyInput(int key, int x, int y)
{
   if (key == GLUT_KEY_DOWN) animationPeriod +=5;
   if( key == GLUT_KEY_UP) 
      if (animationPeriod > 5) animationPeriod -=5;
   glutPostRedisplay();
}
void init(){
	
	glClearColor(0.0,0.0,0.0,1.0);
}
void increaseAngle(void)
{
   ch=++c;
   glutPostRedisplay();
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT );
glColor3f(1.0,1.0,1.0);

 


glRasterPos2i(0.5,0.5);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, ch);
 glutSwapBuffers();
 
 
 }
 void keyInput1(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);
		 }
         break;
         case 'r':ch='a';glutPostRedisplay();break;
         
        case 'c':glutIdleFunc(NULL);break;
      default:
         break;
   }
}
void keyInput2(unsigned char key, int x, int y)
{
   switch (key) 
   {
      case 'r':
         ch='a';
         glutPostRedisplay();
         break;
      case ' ':
        ch=++c;   ;
         glutPostRedisplay();
         break;
      case 27:
         exit(0);
         break;
	  default:
	     break;
   }
}
void specialKeyInput1(int key, int x, int y)
{
   if (key == GLUT_KEY_RIGHT) ch++;
   if( key == GLUT_KEY_LEFT)           ch--;
   glutPostRedisplay();
}

//---------- main
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GL_DOUBLE);
glutInitWindowPosition(500,100);
glutInitWindowSize(320,320);
glutCreateWindow("ascii");
init();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glClearColor(0.5,0.0,0.8,1.0);
glutDisplayFunc(display); 
glutSpecialFunc(specialKeyInput1);
glutKeyboardFunc( keyInput1);


glutMainLoop();
return 0;
}
