-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGasket.cpp
58 lines (50 loc) · 1.24 KB
/
Gasket.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
#include <GL/glut.h>
void DrawGasket(float x1, float y1, float x2, float y2, float x3, float y3, int n)
{
if(n > 0)
{
float x12 = (x1 + x2) / 2;
float y12 = (y1 + y2) / 2;
float x23 = (x2 + x3) / 2;
float y23 = (y2 + y3) / 2;
float x13 = (x3 + x1) / 2;
float y13 = (y3 + y1) / 2;
DrawGasket(x1, y1, x12, y12, x13, y13, n - 1);
DrawGasket(x2, y2, x12, y12, x23, y23, n - 1);
DrawGasket(x3, y3, x23, y23, x13, y13, n - 1);
}
else
{
glBegin(GL_TRIANGLES);
glVertex2f(x1, y1);
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glEnd();
}
}
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.5, 0.5, 1.0);
float x1 = -1.0;
float y1 = -0.4;
float x2 = 0.0;
float y2 = 0.4;
float x3 = 1.0;
float y3 = -0.4;
int n = 2;
DrawGasket(x1, y1, x2, y2, x3, y3, n);
glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600, 400);
glutCreateWindow("Gasket");
glClearColor(1.0, 1.0, 1.0, 1.0);
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glutDisplayFunc(Display);
glutMainLoop();
return 0;
}