#include<GL\glut.h>
#include<math.h>
#include<iostream>

float R = 20;
int f = 0;
float pi = 3.14;
int fb = 0;
float t = 0;

void drawing(){
	glClear(GL_COLOR_BUFFER_BIT);
	glLineWidth(1);
	glLoadIdentity();
	glColor3f(1,0,0);
	glTranslatef(0, 0, 15);
	glBegin(GL_LINE_STRIP);
	for (float t = -10 * pi; t <= 10 * pi; t += pi / 20.0){
		glVertex3f(R * cos(t), t, R * sin(t) - 60.0);
	}
	glEnd();

	glLoadIdentity();
	glColor3f(1, 1, 1);
	glTranslatef(0, -35, 15);
	glTranslatef(R * cos(t), t, R * sin(t) - 60.0);
	glutSolidSphere(2, 50, 5);

	glFlush();
	glutSwapBuffers();
}

void halghe(int value){
	if (f == 1){
		if (t <= 20 * pi){
			t += pi / 20;
			glutPostRedisplay();
			glutTimerFunc(10, halghe, 1);
		}
	}
}



void halgheBack(int value){
	if (fb == 1){
		if (t >= 0 ){
			t -= pi / 20;
			glutPostRedisplay();
			glutTimerFunc(10, halgheBack, 1);
		}
	}
}



void resize(int w, int h){
	glViewport(0, 0, w, h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glFrustum(-10, 10, -10, 10, 5, 100);
	glMatrixMode(GL_MODELVIEW);
}

void setup(){
	glClearColor(0, 0, 0, 0);
}

void specialKeyInput(int key , int x , int y ){
	if (key == GLUT_KEY_UP){ if (f == 0){ f = 1; halghe(1); } else{ f = 0; } }
	if (key == GLUT_KEY_DOWN){
		if (fb == 0){ fb = 1; halgheBack(1); }
		else{ fb = 0; };
	}
	}
	



int main(int x, char**y){
	glutInit(&x, y);
	glutInitWindowSize(500,500);
	glutInitWindowPosition(50,20);
	glutCreateWindow("samimi");

	
	glutDisplayFunc(drawing);
	glutReshapeFunc(resize);


	glutSpecialFunc(specialKeyInput);
	menu();
	setup();
	glutMainLoop();
}