forked from moinul7002/Computer-Graphics-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
70 lines (62 loc) · 1.42 KB
/
main.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
#include<windows.h>
#include<GL/glut.h>
#include<bits/stdc++.h>
using namespace std;
float x, y, len, alpha;
int n;
void line (float x1, float y1, float x2, float y2)
{
glVertex2f(x1,y1);
glVertex2f(x2,y2);
}
void c_curve (float x, float y, float len, float alpha, int n)
{
if(n > 0){
len = len / sqrt(2.0);
c_curve(x, y, len, alpha+45, n-1);
x += len*cos(alpha+45);
y += len*sin(alpha+45);
c_curve(x, y, len, alpha-45, n-1);
}
else{
line(x, y, x+len*cos(alpha), y+len*sin(alpha));
}
}
void myDisplay(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 0.0, 0.0);
glPointSize(1);
glBegin(GL_LINES);
c_curve(x, y, len, alpha, n);
glEnd();
glFlush ();
}
void init (void)
{
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0.7,0.7,0.7,0.7);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-200,500,-200,500);
}
int main(int argc, char** argv)
{
cout<<"Co-ordinate of C(x,y): ";
cin>>x>>y;
cout<<"\nLength: ";
cin>>len;
cout<<"\nAngle: ";
cin>>alpha;
cout<<"\nValue of n: ";
cin>>n;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(850, 600);
glutInitWindowPosition(100, 50);
glutCreateWindow("C CURVE");
init();
glutDisplayFunc(myDisplay);
glutMainLoop();
return 0;
}