user-0 提问: 动态时钟的时间显示和修改

回复:
user: user-1
content: 这样行不？#include<stdio.h> #include<dos.h> #include<conio.h> #include<math.h> #include<graphics.h>  #define PI 3.1415926  void set_black_bg(struct time T,int X,int Y,int R,int RR) {     int X_HOUR,X_MINUTE,X_SECOND ;     int Y_HOUR,Y_MINUTE,Y_SECOND ;     X_HOUR=X+(R/2)*cos(T.ti_hour*2*PI/12+T.ti_min*2*PI/(60*12)-PI/2);     X_MINUTE=X+R*cos(T.ti_min*2*PI/60-PI/2)*3/4 ;     X_SECOND=X+R*cos(T.ti_sec*2*PI/60-PI/2);     Y_HOUR=X+(R/2)*sin(T.ti_hour*2*PI/12+T.ti_min*2*PI/(60*12)-PI/2);     Y_MINUTE=Y+R*sin(T.ti_min*2*PI/60-PI/2)*3/4 ;     Y_SECOND=Y+R*sin(T.ti_sec*2*PI/60-PI/2);     setcolor(BLACK);     line(X,Y,X_HOUR,Y_HOUR);     line(X,Y,X_MINUTE,Y_MINUTE);     line(X,Y,X_SECOND,Y_SECOND); }  int main() {     int X=300,Y=250,R=100,RR=130 ;     int X_HOUR,X_MINUTE,X_SECOND ;     int Y_HOUR,Y_MINUTE,Y_SECOND ;     int X_DRAW=0,Y_DRAW=0,R_DRAW=120 ;     int NUM=0 ;     struct time T ;     struct time temp ;     int gdriver=DETECT,gmode ;     initgraph(&gdriver,&gmode,"D:\\Program Files\\TC\\BGI");     setlinestyle(0,1,3);     setcolor(LIGHTGRAY);     circle(X,Y,RR);     setlinestyle(0,1,1);     for(NUM=0;NUM<12;NUM++)     {         setcolor(11);         X_DRAW=X+R_DRAW*cos(NUM*2*PI/12);         Y_DRAW=Y+R_DRAW*sin(NUM*2*PI/12);         circle(X_DRAW,Y_DRAW,5);         setfillstyle(1,11);         if((NUM%3)==0)floodfill(X_DRAW,Y_DRAW,11);              }     temp.ti_sec=100 ;     while(!kbhit())     {         gettime(&T);         if(temp.ti_sec!=T.ti_sec)         {             set_black_bg(temp,300,250,100,130);             temp=T ;             X_HOUR=X+(R/2)*cos(T.ti_hour*2*PI/12+T.ti_min*2*PI/(60*12)-PI/2);             X_MINUTE=X+R*cos(T.ti_min*2*PI/60-PI/2)*3/4 ;             X_SECOND=X+R*cos(T.ti_sec*2*PI/60-PI/2);             Y_HOUR=X+(R/2)*sin(T.ti_hour*2*PI/12+T.ti_min*2*PI/(60*12)-PI/2);             Y_MINUTE=Y+R*sin(T.ti_min*2*PI/60-PI/2)*3/4 ;             Y_SECOND=Y+R*sin(T.ti_sec*2*PI/60-PI/2);             setcolor(YELLOW);             line(X,Y,X_HOUR,Y_HOUR);             setcolor(RED);             line(X,Y,X_MINUTE,Y_MINUTE);             setcolor(BLUE);             line(X,Y,X_SECOND,Y_SECOND);         }     }     getch();     closegraph();     return 0 ; }

user: user-0
content: 自己顶一下。

user: user-2
content: 仅供参考#include <graphics.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dos.h> #include <conio.h> #include <time.h> #include <math.h> time_t t; char timestr1[30];//DDD MMM dd hh:mm:ss YYYY char timestr2[30];//DDD MMM dd hh:mm:ss YYYY char hhmmss[9]; int graphdriver,graphmode,page; int i,xo,yo,r0,r1,r2,r3,r4,r5,r6,r7; int x1,y1,x2,y2; int hh,mm,ss; double c,s; int xasp,yasp; void main() {     xo=60;yo=60;     r0=5; //轴     r1=20;//时针     r2=36;//分针     r3=45;//秒针     r4=50;//时刻度     r5=53;//分刻度     r6=55;//刻度外     r7=59;//表盘     graphdriver=VGA;     graphmode=VGAMED;     initgraph(&graphdriver,&graphmode,"D:\\BC\\BGI");     getaspectratio(&xasp, &yasp);     page=0;     timestr2[0]=0;     while (1) {         if (kbhit()) break;         time(&t);         strcpy(timestr1,ctime(&t));         if (strcmp(timestr1,timestr2)) {             strcpy(timestr2,timestr1);             hh=atoi(timestr2+11);             mm=atoi(timestr2+14);             ss=atoi(timestr2+17);             setvisualpage(page);             setactivepage(1-page);             cleardevice();             sprintf(hhmmss,"%02d:%02d:%02d",hh,mm,ss);             outtextxy(28,0,hhmmss);             pieslice(xo,yo,0,360,r0);             circle(xo,yo,r7);             for (i=0;i<60;i++) {                 c=cos(i*6*3.14159265/180);                 s=sin(i*6*3.14159265/180)*xasp/yasp;                 if (0==(i%5)) {                     x1=xo+r4*c;                     y1=yo+r4*s;                 } else {                     x1=xo+r5*c;                     y1=yo+r5*s;                 } 				x2=xo+r6*c; 				y2=yo+r6*s; 				line(x1,y1,x2,y2); 				if (((hh%12)*5+mm/12+45)%60==i) { 					x2=xo+r1*c; 					y2=yo+r1*s; 					setlinestyle(0,-1,3); 					line(xo,yo,x2,y2); 					setlinestyle(0,-1,1); 				} 				if ((mm+45)%60==i) { 					x2=xo+r2*c; 					y2=yo+r2*s; 					setlinestyle(0,-1,3); 					line(xo,yo,x2,y2); 					setlinestyle(0,-1,1); 				} 				if ((ss+45)%60==i) { 					x2=xo+r3*c; 					y2=yo+r3*s; 					line(xo,yo,x2,y2); 				} 			} 			page=1-page; 		}         delay(100);     }     getch();     closegraph(); }