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
| #include <graphics.h> #include <conio.h> #include <math.h> #define PI 3.1415926536 void DrawHand(int hour, int minute, int second) { double a_hour, a_min, a_sec; int x_hour, y_hour, x_min, y_min, x_sec, y_sec; a_sec = second * 2 * PI / 60; a_min = minute * 2 * PI / 60 + a_sec / 60; a_hour= hour * 2 * PI / 12 + a_min / 12; x_sec = int(120 * sin(a_sec)); y_sec = int(120 * cos(a_sec)); x_min = int(100 * sin(a_min)); y_min = int(100 * cos(a_min)); x_hour= int(70 * sin(a_hour)); y_hour= int(70 * cos(a_hour)); setlinestyle(PS_SOLID, 10); setcolor(WHITE); line(320 + x_hour, 240 - y_hour, 320 - x_hour / 7, 240 + y_hour / 7); setlinestyle(PS_SOLID, 6); setcolor(LIGHTGRAY); line(320 + x_min, 240 - y_min, 320 - x_min / 5, 240 + y_min / 5); setlinestyle(PS_SOLID, 2); setcolor(RED); line(320 + x_sec, 240 - y_sec, 320 - x_sec / 3, 240 + y_sec / 3); } void DrawDial() { circle(320, 240, 2); circle(320, 240, 60); circle(320, 240, 160); outtextxy(296, 310, "BestAns"); int x, y; for (int i=0; i<60; i++) { x = 320 + int(145 * sin(PI * 2 * i / 60)); y = 240 + int(145 * cos(PI * 2 * i / 60)); if (i % 15 == 0) bar(x - 5, y - 5, x + 5, y + 5); else if (i % 5 == 0) circle(x, y, 3); else putpixel(x, y, WHITE); } } void main() { initgraph(640, 480); DrawDial(); setwritemode(R2_XORPEN); SYSTEMTIME ti; while(!kbhit()) { GetLocalTime(&ti); DrawHand(ti.wHour, ti.wMinute, ti.wSecond); Sleep(1000); DrawHand(ti.wHour, ti.wMinute, ti.wSecond); } closegraph(); }
|