简单的时钟程序
#include <graphics.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#define _CRT_SECURE_NO_DEPRECATE
#define pi 3.1415926
int main() {
time_t t;
int i = 0;
struct tm* nowTime;
int hour, min, sec;
initgraph(640, 480);
while (1) {
for (i = 0; i <= 59; i++) {
if (i % 5 == 0) {
line(320 + 170 * sin(i * pi / 30), 240 - 170 * cos(i * pi / 30), 320 + 200 * sin(i * pi / 30), 240 - 200 * cos(i * pi / 30));
}
else {
line(320 + 185 * sin(i * pi / 30), 240 - 185 * cos(i * pi / 30), 320 + 200 * sin(i * pi / 30), 240 - 200 * cos(i * pi / 30));
}
}
circle(320, 240, 200);
time(&t);
nowTime = localtime(&t);
hour = nowTime->tm_hour;
min = nowTime->tm_min;
sec = nowTime->tm_sec;
setlinecolor(WHITE);
line(320, 240, 320 + 60 * sin(pi * hour / 6), 240 - 60 * cos(pi * hour / 6));
line(320, 240, 320 + 100 * sin(pi * min / 30), 240 - 100 * cos(pi * min / 30));
line(320, 240, 320 + 160 * sin(pi * sec / 30), 240 - 160 * cos(pi * sec / 30));
Sleep(100);
cleardevice();
}
getchar();
closegraph();
return 0;
}