-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreflectionFromLine.c
More file actions
152 lines (134 loc) · 2.59 KB
/
reflectionFromLine.c
File metadata and controls
152 lines (134 loc) · 2.59 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include<stdio.h>
#include <stdlib.h>
#include<GL/glut.h>
#include <unistd.h>
#include<math.h>
#define PI 3.1415926535897932384626433832795
double Point[100][2];
int k=0;
int numbPoint=0;
void type(char *string, double X, double Y)
{
char *c;
glColor3f(1.0, 1.0, 1.0);
glRasterPos2f(X+1,Y);
for (c=string; *c != '\0'; c++)
{
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, *c);
}
}
void DrawAxis()
{
glLineWidth(1);
glBegin(GL_LINES);
glColor3f(0.0,1.0,0.8);
glVertex2f(-500, 0);
glVertex2f(500, 0);
glVertex2f(0, 500);
glVertex2f(0, -500);
glEnd();
}
void DrawLine()
{
glLineWidth(1);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex2f(500, -2008/2);
glVertex2f(-1008/4, 500);
glEnd();
type("4x + 2y + 8 = 0", -1008/4 + 15, 470);
type("MIRROR",-1008/4 + 20, 455);
glFlush();
}
void myName()
{
glClear(GL_COLOR_BUFFER_BIT);
type("Ayush Jain", -495, 490);
type("CSE-CCVT B-1",-495, 475);
type("R110217039",-495, 460);
DrawAxis();
DrawLine();
glFlush();
}
// function to initialize
void myInit (void)
{
// making background color black as first
// 3 arguments all are 0.0
gluOrtho2D(-500,500,-500,500);
glClearColor(0.0, 0.0, 0.0, 0.0);
myName();
}
void Draw()
{
glLineWidth(3);
glBegin(GL_LINE_LOOP);
for(int i=k; i<numbPoint; i++)
{
glColor3f(1.0,1.0,1.0);
glVertex2f(Point[i][0], Point[i][1]);
}
glEnd();
glFlush();
//k = numbPoint;
}
void reflect()
{
double x,y;
for(int i=k; i<numbPoint; i++)
{
x = (-3*Point[i][0]/5) - (4*Point[i][1]/5) - 16/5;
y = (-4*Point[i][0]/5) + (3*Point[i][1]/5) - (4/5);
Point[i][0] = x;
Point[i][1] = y;
}
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
myName();
Draw();
}
void store(double X, double Y)
{
Point[numbPoint][0] = X;
Point[numbPoint++][1] = Y;
glPointSize(2);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POINTS);
glVertex2f(X,Y);
glEnd();
glFlush();
}
static void Key(unsigned char key, int x, int y)
{
switch (key)
{
case 32:
Draw();
break;
}
}
void mouseClick(int button, int state, int X, int Y)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
store(X-500,(500-Y));
}
if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
reflect();
}
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// giving window size in X- and Y- direction
glutInitWindowSize(1000, 1000);
// Giving name to window
glutCreateWindow("Reflection about an arbitrary line: 4x + 2y + 8 = 0");
myInit();
glutKeyboardFunc(Key);
glutMouseFunc(mouseClick);
glutMainLoop();
return 0;
}