大学时写的一些小程序-8,c桌面时钟 - 小lu

大学时写的一些小程序-8(c桌面时钟)

#include<graphics.h>

#include<conio.h>

#include<math.h>

#include<dos.h>

#define LH 55

#define LM 90

#define LS 133

#define LEG 200

#define LEG2 193

#define DUL 185

main()

{

int gdriver,gmode,i,j;

float x[13],y[13];

float xs,ys,xm,ym,xh,yh;

float h=100,m=200,s=100;

float x1[61],y1[61],x2[61],y2[61];

gdriver=DETECT;

textbackground(5);

textcolor(BLUE);

clrscr();

while(h>=12)

{printf("\n\n\nplease input the hour(h<12):\n");

scanf("%f",&h);

clrscr();

}

while(m>=60)

{ printf("\n\n\nplease input the mint(m<60):\n");

scanf("%f",&m);

clrscr();}

while(s>=60)

{printf("\n\n\nplease input the sect(s<60):\n");

scanf("%f",&s);

clrscr();}

sleep(1);

printf("\n\n\nthe current time is:%0.0f:%0.0f:%0.0f\n\n",h,m,s);

sleep(1);

printf("wait 2 seconds for initcolok...");

sleep(2);

clrscr();

/*图形处理函数*/

gdriver=DETECT;

initgraph(&gdriver,&gmode,"c:\\wexam\\TC");

cleardevice();

x[0]=300;y[0]=240;

for(i=1;i<=3;i++)

{x[i]=x[0]+DUL*sin(M_PI/6*i);

y[i]=y[0]-DUL*cos(M_PI/6*i);}

for(i=4;i<=6;i++)

{x[i]=x[0]+DUL*cos(M_PI/6*(i-3));

y[i]=y[0]+DUL*sin(M_PI/6*(i-3));}

for(i=7;i<=9;i++)

{x[i]=x[0]-DUL*sin(M_PI/6*(i-6));

y[i]=y[0]+DUL*cos(M_PI/6*(i-6));}

for(i=10;i<=12;i++)

{x[i]=x[0]-DUL*cos(M_PI/6*(i-9));

y[i]=y[0]-DUL*sin(M_PI/6*(i-9));}

while(1)

{

cleardevice();

setbkcolor(GREEN);

setcolor(5);

settextstyle(0,0,1);

outtextxy(x[0]-52,y[0]+25,"made by ujn.lu");

setcolor(RED);

settextstyle(0,0,2);

circle(x[0],y[0],LEG);/*画圆*/

outtextxy(x[12],y[12],"12");

outtextxy(x[1],y[1],"1");

outtextxy(x[2],y[2],"2");

outtextxy(x[3],y[3],"3");

outtextxy(x[4],y[4],"4");

outtextxy(x[5],y[5],"5");

outtextxy(x[6],y[6],"6");

outtextxy(x[7],y[7],"7");

outtextxy(x[8],y[8],"8");

outtextxy(x[9],y[9],"9");

outtextxy(x[10],y[10],"10");

outtextxy(x[11],y[11],"11");

outtextxy(x[12],y[12],"12");

setfillstyle(SOLID_FILL,BLACK);

circle(x[0],y[0],8);

for(i=1;i<=60;i++)

{x1[i]=x[0]+LEG*sin(M_PI*i/30);

y1[i]=y[0]+LEG*cos(M_PI*i/30);

x2[i]=x[0]+LEG2*sin(M_PI*i/30);

y2[i]=y[0]+LEG2*cos(M_PI*i/30);

line(x1[i],y1[i],x2[i],y2[i]); }

/*进行时间分析*/

s++;

m+=(s/(360*60*2*M_PI));

h+=(m/(360*2*60*M_PI))+(s/(360*2*3600*M_PI*360*2*M_PI));

if(s>=60) {s=0;m++;}

if(m>=60){m=0;h++;}

if(h>=12){h=0;}

if(h>=0&&h<=3)

{xh=x[0]+LH*sin(M_PI*h/6);

yh=y[0]-LH*cos(M_PI*h/6);}

if(h>3&&h<=6)

{xh=x[0]+LH*cos(M_PI*(h-3)/6);

yh=y[0]+LH*sin(M_PI*(h-3)/6);}

if(h>6&&h<=9)

{xh=x[0]-LH*sin(M_PI*(h-6)/6);

yh=y[0]+LH*cos(M_PI*(h-6)/6);}

if(h>9&&h<12)

{xh=x[0]-LH*cos(M_PI*(h-9)/6);

yh=y[0]-LH*sin(M_PI*(h-9)/6);}

setcolor(BLUE);

setlinestyle(0,0,3);

line(x[0],y[0],xh,yh);

if(m>=0&&m<=15)

{xm=x[0]+LM*sin(M_PI*m/30);

ym=y[0]-LM*cos(M_PI*m/30);}

if(m>15&&m<=30)

{xm=x[0]+LM*cos(M_PI*(m-15)/30);

ym=y[0]+LM*sin(M_PI*(m-15)/30);}

if(m>30&&m<=45)

{xm=x[0]-LM*sin(M_PI*(m-30)/30);

ym=y[0]+LM*cos(M_PI*(m-30)/30);}

if(m>45&&m<60)

{xm=x[0]-LM*cos(M_PI*(m-45)/30);

ym=y[0]-LM*sin(M_PI*(m-45)/30);}

setcolor(YELLOW);

setlinestyle(0,0,2);

line(x[0],y[0],xm,ym);

if(s>=0&&s<=15)

{xs=x[0]+LS*sin(M_PI*s/30);

ys=y[0]-LS*cos(M_PI*s/30);}

if(s>15&&s<=30)

{xs=x[0]+LS*cos(M_PI*(s-15)/30);

ys=y[0]+LS*sin(M_PI*(s-15)/30);}

if(s>30&&s<=45)

{xs=x[0]-LS*sin(M_PI*(s-30)/30);

ys=y[0]+LS*cos(M_PI*(s-30)/30);}

if(s>45&&s<60)

{xs=x[0]-LS*cos(M_PI*(s-45)/30);

ys=y[0]-LS*sin(M_PI*(s-45)/30);}

setcolor(RED);

setlinestyle(0,0,1);

line(x[0],y[0],xs,ys);

sleep(1);

}

}

发表于 2009-12-11 16:33 小lu 阅读(444) 评论(0) 编辑收藏举报