1 #include<graphics.h> 2 #include<conio.h> 3 #include<math.h> 4 #include<stdio.h> 5 #include<windows.h> 6 #include<iostream.h> 7 #define PI 3.1415926 8 void Draw(int hour,int minute,int second) 9 { 10 double a_hour,a_min,a_sec; 11 int x_hour,y_hour,x_min,y_min,x_sec,y_sec; 12 int x_hour1,y_hour1,x_min1,y_min1,x_sec1,y_sec1; 13 a_sec = second*2*PI/60; 14 a_min = minute*2*PI/60+a_sec/60; 15 a_hour= hour*2*PI/12+a_min/12; 16 x_sec = 320 +(int)(115 * sin(a_sec)); 17 y_sec = 240 -(int)(115 * cos(a_sec)); 18 x_min = 320 + (int)(100 * sin(a_min)); 19 y_min = 240 - (int)(100 * cos(a_min)); 20 x_hour= 320 + (int)(70 * sin(a_hour)); 21 y_hour= 240 - (int)(70 * cos(a_hour)); 22 /*------------------------------------------------------*/ 23 x_sec1 = 320 +(int)(30 * sin(a_sec)); 24 y_sec1 = 240 -(int)(30 * cos(a_sec)); 25 x_min1 = 320 + (int)(20 * sin(a_min)); 26 y_min1 = 240 - (int)(20 * cos(a_min)); 27 x_hour1= 320 + (int)(20 * sin(a_hour)); 28 y_hour1= 240 - (int)(20 * cos(a_hour)); 29 setlinestyle(PS_SOLID,6); 30 setcolor(WHITE); 31 line(320,240,x_hour,y_hour); 32 line(320, 240, 640-x_hour1,480-y_hour1 ); 33 setlinestyle(PS_SOLID,4); 34 setcolor(LIGHTGRAY); 35 line(320, 240, x_min, y_min); 36 line(320, 240, 640-x_min1,480-y_min1 ); 37 setlinestyle(PS_SOLID,2); 38 setcolor(RED); 39 line(320, 240, x_sec, y_sec); 40 //line(320, 240, x_sec1, y_sec1); 41 line(320, 240, 640-x_sec1,480-y_sec1 ); 42 } 43 void main(void) 44 { 45 initgraph(640,480); 46 /*----------------------------------------------------------------*/ 47 circle(320,240,4); 48 circle(320,240,115); 49 circle(320,240,120); 50 rectangle(300,360,340,400); 51 rectangle(250,400,390,440); 52 circle(200,120,50); 53 circle(200,120,45); 54 55 circle(440,120,50); 56 circle(440,120,45); 57 outtextxy(210,235,'9'); 58 outtextxy(425,235,'3'); 59 outtextxy(315,130,"12"); 60 outtextxy(315,339,'6'); 61 outtextxy(262,322,'7'); 62 outtextxy(260,145,"11"); 63 64 outtextxy(370,322,'5'); 65 outtextxy(370,145,'1'); 66 outtextxy(225,287,'8'); 67 outtextxy(408,287,'4'); 68 outtextxy(222,185,"10"); 69 outtextxy(410,181,'2'); 70 outtextxy(180,110,"月"); 71 outtextxy(220,110,"日"); 72 outtextxy(410,110,"星期"); 73 /*----------------------------------------------------------------*/ 74 setwritemode(R2_XORPEN); 75 SYSTEMTIME ti; // SYSTEMTIME是一个结构体 // 76 char Second_R[1],Second_L[1]; 77 char Minute_R[1],Minute_L[1]; 78 char Hour_R[1],Hour_L[1]; 79 while(!kbhit()) 80 { 81 GetLocalTime(&ti); 82 // 把当前的时间给结构体变量ti,让它保存数据,用&ti作为实参是因为形参是指针,指针进行操作,直接改变原来的数据 // 83 /*----------------------------------------------------------------*/ 84 switch(ti.wDayOfWeek) 85 { 86 case 0: setcolor(LIGHTRED); 87 outtextxy(450,110,"日"); 88 break; 89 case 1: setcolor(YELLOW); 90 outtextxy(450,110,"一"); 91 break; 92 case 2: setcolor(LIGHTCYAN); 93 outtextxy(450,110,"二"); 94 break; 95 case 3: setcolor(LIGHTBLUE); 96 outtextxy(450,110,"三"); 97 break; 98 case 4: setcolor(LIGHTGREEN); 99 outtextxy(450,110,"四"); 100 break; 101 case 5: setcolor(LIGHTMAGENTA); 102 outtextxy(450,110,"五"); 103 break; 104 case 6: setcolor(RGB(255,128,0)); 105 outtextxy(450,110,"六"); 106 break; 107 } 108 /*----------------------------------------------------------------*/ 109 110 char Day[2],Month[2],Year[4]; 111 setcolor(CYAN); 112 sprintf(Month,"%d",ti.wMonth); 113 outtextxy(160,110,Month); 114 sprintf(Day,"%d",ti.wDay); 115 outtextxy(205,110,Day); 116 117 setcolor(LIGHTMAGENTA); 118 sprintf(Year,"%d",ti.wYear); 119 outtextxy(305,370,Year); 120 /*----------------------------------------------------------------*/ 121 Draw(ti.wHour,ti.wMinute,ti.wSecond); 122 /*----------------------------------------------------------------*/ sprintf(Hour_R, "%d", ti.wHour %10); 123 sprintf(Hour_L,"%d", (int)ti.wHour /10); 124 outtextxy(272,420,Hour_L); 125 outtextxy(280,420,Hour_R); 126 outtextxy(300,420,':'); 127 128 sprintf(Minute_R, "%d", ti.wMinute %10); 129 sprintf(Minute_L,"%d", (int)ti.wMinute /10); 130 outtextxy(312,420,Minute_L); 131 outtextxy(320,420,Minute_R); 132 outtextxy(340,420,':'); 133 134 sprintf(Second_R, "%d", ti.wSecond %10); 135 sprintf(Second_L,"%d", (int)ti.wSecond /10); 136 outtextxy(352,420,Second_L); 137 outtextxy(360,420,Second_R); 138 Sleep(1000); 139 Draw(ti.wHour,ti.wMinute,ti.wSecond); 140 } 141 142 /*----------------------------------------------------------------*/ 143 144 getch(); 145 closegraph(); 146 }