-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClock.cpp
More file actions
185 lines (158 loc) · 4.01 KB
/
Clock.cpp
File metadata and controls
185 lines (158 loc) · 4.01 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#include<iostream>
// #include<windows.h>
#include<GL/glut.h>
// #include<gl/GL.h>
// #include<glut.h>
#include<math.h>
#define PI 3.141592653589793
GLfloat secAngle=0.0;
GLfloat minAngle=0.0;
GLfloat hourAngle=0.0;
GLfloat hour=0.0;
GLfloat x1=0.0;
GLfloat y2=0.0;
GLfloat z1=0.0;
GLfloat radius = 10.0;
GLfloat smallradius = 3.0;
int angle;
void smallLines(GLfloat,GLfloat,GLfloat,GLfloat,GLfloat,int);
void secondsLine(void);
void minutesLines(void);
void hourLine(void);
void centerpoint(void);
void cirlce(void);
void myInit(void)
{
glColor3f(1.0f,0.0f,0.0f);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void DrawClock()
{
char buff[100];
glLoadIdentity();
glClearColor(1.0, 1.0, 1.0, 1.0);
glOrtho(0.0, 20.0, 0.0, 20.0, -10.0, 10.0);
glClear(GL_COLOR_BUFFER_BIT);
}
// ------------------------------- Circle -------------------------------------------
void cirlce()
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glPushMatrix();
glTranslatef(10.0, 10.0, 10.0);
glColor3f(0.9,0.9,0.9);
glBegin(GL_TRIANGLE_FAN);
glVertex3f(x1, y2, z1);
for(angle=0; angle <= 360; angle +=1)
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y2 + sin(angle * PI/180.0f) * radius, z1);
glEnd();
glPopMatrix();
}
// ------------------------------- Small Lines ---------------------------------------
void smallLines(GLfloat x1,GLfloat y2,GLfloat z1,GLfloat radius,GLfloat smallradiu,int angle)
{
glPushMatrix();
glTranslatef(10.0, 10.0, 0.0);
glColor3f(0.2,0.2,0.2);
glLineWidth(2);
for(angle=0; angle <= 360; angle +=30)
{
glBegin(GL_LINES);
if(angle == 0.0 || angle==90.0 || angle == 180.0 || angle == 270.0 || angle == 360.0 )
{
glColor3f(1.0,0.2,0.2);
glVertex3f(x1 + cos(angle * PI/180.0f)* (radius-1.2), y2 + sin(angle * PI/180.0f) * (radius-1.2), z1+0.1);
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y2 + sin(angle * PI/180.0f) * radius, z1+0.1);
}
else
{
glColor3f(0.2,0.2,0.2);
glVertex3f(x1 + cos(angle * PI/180.0f)* (radius-0.5), y2 + sin(angle * PI/180.0f) * (radius-0.5), z1);
glVertex3f(x1 + cos(angle * PI/180.0f)* radius, y2 + sin(angle * PI/180.0f) * radius, z1);
}
glEnd();
}
glPopMatrix();
}
// ------------------------------- Center Point ---------------------------------------
void centerpoint()
{
glColor3f(0.0,0.0,0.0);
glPointSize(8.0);
glPushMatrix();
glTranslatef(10.0, 10.0, 0.0);
glBegin(GL_POINTS);
glVertex3f(0.0,0.0,0.0);
glEnd();
glPopMatrix();
//glFlush();
}
// ------------------------------- Seconds Line ---------------------------------------
void secondsLine()
{
glColor3f(1.0,1.0,0.0);
glLineWidth(2.0);
glPushMatrix();
glTranslatef(10.0, 10.0, 0.0);
glRotatef(-secAngle,0.0,0.0,1.0);
glBegin(GL_LINES);
glVertex2f(0,0);
glVertex2f(7,7);
glEnd();
glPopMatrix();
}
// ------------------------------- Minutes Line ---------------------------------------
void minutesLines()
{
glColor3f(1.0,0.0,0.0);
glLineWidth(2.0);
glPushMatrix();
glTranslatef(10.0, 10.0, 0.0);
glRotatef(-minAngle, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 1.0);
glVertex3f(0.0, 7.0, 1.0);
glEnd();
glPopMatrix();
}
// ------------------------------- Hour Line ------------------------------------------
void hourLine()
{
glColor3f(0.0,1.0,0.0);
glLineWidth(3.0);
glPushMatrix();
glTranslatef(10.0, 10.0, 0.0);
glRotatef(-hourAngle, 0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 6.5, 0.0);
glEnd();
glPopMatrix();
}
// ------------------------------- Idel Function ---------------------------------------
void Idle(void)
{
secAngle += 0.1;
hourAngle += 0.01;
minAngle += 0.2;
cirlce();
smallLines(x1,y2,z1,radius,smallradius,angle);
centerpoint();
secondsLine();
minutesLines();
hourLine();
glFlush();
}
int main(int argc , char **argv)
{
glutInit(&argc , argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(600,600);
glutInitWindowPosition(200,300);
glutCreateWindow("Analog Clock");
glutDisplayFunc(DrawClock);
glutIdleFunc(Idle);
myInit();
glutMainLoop();
}