Pendulam Movement Opengl program in c

Pendulam Movement Opengl program in c

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

double angle,degree,x,y;
const  double  pi2 = 6.28318530718;
const  double  cord_length = 1;

double theta = 0.0;
static double radius = 0.017;


void display(){

double delta_theta = pi2/40;

while(1){

for(angle=270;angle>180;angle--){

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex2f(0.0,0.0);

degree = (angle * 3.14/180);
x = cord_length*(cos(degree) - sin(degree));
y = cord_length*(sin(degree) + cos(degree));
glVertex2f(x,y);

glEnd();

theta = 0.0;
if(angle>225){
glColor3f(-x-y+0.5, 0.0, 0.0);
}else{
glColor3f(x-y+0.5, 0.0, 0.0);
}

glBegin(GL_POLYGON);
while (theta <= pi2) {
x = x + radius * (cos(theta));
    y = y + radius * (sin(theta));
    //printf("%f-%f, ",x,y);
   glVertex2f(x, y);
   theta += delta_theta;
};

glEnd();
glutSwapBuffers();

}


for(angle=180;angle<270;angle++){

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex2f(0.0,0.0);

degree = (angle * 3.14/180);
x = cord_length*(cos(degree) - sin(degree));
y = cord_length*(sin(degree) + cos(degree));
glVertex2f(x,y);

glEnd();

theta = 0.0;
if(angle<225){
glColor3f(x-y+0.5, 0.0, 0.0);
}else{
glColor3f(-x-y+0.5, 0.0, 0.0);
}

glBegin(GL_POLYGON);
while (theta <= pi2) {
x = x+ radius * (cos(theta));
    y = y+ radius * (sin(theta));
    //printf("%f-%f, ",x,y);
   glVertex2f(x, y);
   theta += delta_theta;
};
glEnd();

glutSwapBuffers();

}

}

}
void winInit(){

glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
gluOrtho2D(-2, 2, -2, 2);


}

main(int argc, char *argv[]){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(5,5);
glutInitWindowSize(600,600);
glutCreateWindow("Pendulum");
winInit();


glutDisplayFunc(display);
glutMainLoop();
return 0;


}
Copyright © C Program | Java | OpenGL Programming | Hadoop at Computaholics