-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTriangle Animation.cpp
65 lines (53 loc) · 1.11 KB
/
Triangle 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
#include <GL/glut.h>
#include <bits/stdc++.h>
using namespace std;
float x1 = -0.2, yy1 = 0.0, x2 = 0.2, y2 = 0.0, x3 = 0.0, y3 = 0.5;
bool flag = 1;
void idle()
{
if(flag)
{
x1 -= 0.0001;
x2 += 0.0001;
x3 = (x1+x2) / 2;
if(x2 >= 0.9f)
flag = 0;
}
else
{
x1 += 0.0001;
x2 -= 0.0001;
x3 = (x1+x2) / 2;
if(x2 <= 0.2f)
flag = 1;
}
glutPostRedisplay();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPushMatrix();
glColor3f(0, 0, 1.0);
glBegin(GL_POLYGON); //Begin triangle coordinates
//Triangle
glVertex2f(x1, yy1);
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glEnd(); //End triangle coordinates
glPopMatrix();
glutSwapBuffers();
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutCreateWindow("Animation");
glClearColor(0.1f, 0.5f, 0.9f, 1.0f);
glutDisplayFunc(display);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}