-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrandomClickOctagon.c
100 lines (90 loc) · 1.92 KB
/
randomClickOctagon.c
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
#include<stdio.h>
#include<GL/glut.h>
#include <unistd.h>
#include<math.h>
#define PI 3.1415926535897932384626433832795
#define MAX_CLICK 3
int k=0;
int count=0;
int numbPoint=0;
double mousex, mousey;
// function to initialize
void myInit (void)
{
// making background color black as first
// 3 arguments all are 0.0
glClearColor(0.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void draw(double X, double Y)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_LOOP);
for (double i = 0;i < 2*PI;i +=2*PI/ 8 )
{
glVertex2f( X + 0.2 * cos(i), Y + 0.2 * sin(i));
}
glEnd();
glFlush();
}
void show(double X, double Y)
{
for(double j=0.2; j<=0.5; j+=0.0001)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(j+j, 1.0-j-j, j+j+j);
glBegin(GL_LINE_LOOP);
for (double i = 0;i < 2*PI;i +=2*PI/ 8 )
{
glVertex2f( X + j * cos(i), Y + j * sin(i));
}
glEnd();
glFlush();
}
for(double j=0.5; j>=0.2; j-=0.0001)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(j+j, 1.0-j-j, j+j+j);
glBegin(GL_LINE_LOOP);
for (double i = 0;i < 2*PI;i +=2*PI/ 8 )
{
glVertex2f( X + j * cos(i), Y + j * sin(i));
}
glEnd();
glFlush();
}
}
static void Key(unsigned char key, int x, int y)
{
switch (key) {
case 27:
glutDestroyWindow(1);
break;
case 32:
show(mousex, mousey);
}
}
void mouseClick(int button, int state, int X, int Y)
{
if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mousex= (X-250)*(2.0/500);
mousey = (250-Y)*(2.0/500);
draw((X-250)*(2.0/500),(250-Y)*(2.0/500));
glClear(GL_COLOR_BUFFER_BIT);
}
}
int main (int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
// giving window size in X- and Y- direction
glutInitWindowSize(500, 500);
// Giving name to window
glutCreateWindow("Random");
myInit();
glutKeyboardFunc(Key);
glutMouseFunc(mouseClick);
glutMainLoop();
}