-
Notifications
You must be signed in to change notification settings - Fork 0
/
13. animation.cpp
72 lines (59 loc) · 1.25 KB
/
13. animation.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include<iostream>
#include<math.h>
#include<time.h>
#include<GL/glut.h>
using namespace std;
int x=0;
int flag =0;
void init()
{
glClearColor(1.0 ,1.0 ,1.0 ,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 640 , 0 ,480);
}
void object1()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1 , 0 ,0);
glBegin(GL_POLYGON);
glVertex2i(x , 220);
glVertex2i(x+40 , 220);
glVertex2i(x+40, 260);
glVertex2i(x , 260);
glEnd();
glutSwapBuffers();
}
void timer(int)
{
glutPostRedisplay();
glutTimerFunc(1000/60 , timer , 0);
if(flag==0)
{
x = x+3;
}
if(flag==1)
{
x = x-3;
}
if(x == 600)
{
flag = 1;
}
if(x == 0)
{
flag =0;
}
}
int main(int argc , char **argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(640 , 480);
glutInitWindowPosition(200 , 200);
glutCreateWindow("Animation");
init();
glutDisplayFunc(object1);
glutTimerFunc(1000 , timer , 0);
glutMainLoop();
return 0;
}