| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 673 人关注过本帖
标题:[原创][讨论]C编写的时钟
只看楼主 加入收藏
zhangpeng
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-9
收藏
 问题点数:0 回复次数:4 
[原创][讨论]C编写的时钟


#include <graphics.h>
#include <math.h>
#include <stdio.h>
#include <dos.h>
#define pi 3.1415926
main()
{
int gdriver,gmode,errorcode;
int x,y,i,angleHou,angleMin,angleSec;
long size;
char text[2],*buf;
struct time tim;
detectgraph(&gdriver,&gmode);
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("graphicx error: %s\n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
exit(1);
}
initgraph(&gdriver,&gmode,"");
if(errorcode!=grOk)
{
printf("graphicx error: %s\n",grapherrormsg(errorcode));
printf("press any key to halt:");
getch();
exit(1);
}

/*draw three circles*/
setbkcolor(1);
setcolor(100);
circle(300,250,150);
setcolor(50);
circle(300,250,145);
setcolor(150);
circle(300,250,140);
/*set the hour's number*/
for(i=1;i<=12;i++)
{
x=300+130*sin((i*30)*pi/180);
y=250-130*cos((i*30)*pi/180);
sprintf(text,"%d",i);
outtextxy(x,y,text);
}
/*set the minute's number*/
for(i=1;i<=60;i++)
{
x=300+130*sin((i*6)*pi/180);
y=250-130*cos((i*6)*pi/180);
setcolor(255);
outtextxy(x,y,".");
}
size=imagesize(150,100,450,400);
buf=malloc(size);
getimage(150,100,450,400,buf);

/*get the time*/
while(1)
{ gettime(&tim);
angleHou=tim.ti_hour;
angleMin=tim.ti_min;
angleSec=tim.ti_sec;
putimage(150,100, buf, COPY_PUT);

/*count the position */

second(angleSec);
minute(angleMin);
hour(angleHou);

}

}

second(int angleSec)
{
int x,y;
while(kbhit())
{
closegraph();
exit(1);
}
x=300+115*sin((angleSec*6)*pi/180);
y=250-115*cos((angleSec*6)*pi/180);
setcolor(3);
line(300,250,x,y);

}
minute(int angleMin)
{
int x,y;
x=300+110*sin((angleMin*6)*pi/180);
y=250-110*cos((angleMin*6)*pi/180);
setcolor(4);
line(300,250,x,y);

}
hour(int angleHou)
{ int x,y,i,angleMin;
struct time tim;
gettime(&tim);
angleMin=tim.ti_min;
i=(angleMin*5)/60;
x=300+100*sin((angleHou*30+i*6)*pi/180);
y=250-100*cos((angleHou*30+i*6)*pi/180);
setcolor(5);
line(300,250,x,y);

}



搜索更多相关主题的帖子: 时钟 include errorcode 编写 
2006-04-23 19:58
沉路
Rank: 1
等 级:新手上路
帖 子:36
专家分:0
注 册:2005-5-15
收藏
得分:0 

还不错!就是针闪得太厉害了!


我的博客:http://tongshengyuan. 我的博客:http://sanweishuwu2005.
2006-04-23 22:14
gaga
Rank: 1
等 级:新手上路
威 望:2
帖 子:307
专家分:0
注 册:2006-4-5
收藏
得分:0 
强啊
楼主
都用到什么知识了啊
我学了C还不知道可以这样编写
要是能让它自己走起来就更好了呵呵

明天的明天还有明天。 可是今天却只有一个。 public Copy from 无缘今生
2006-04-24 01:40
zhangpeng
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-9
收藏
得分:0 

是的我会继续修改修改!
我一时也说不上来!


2006-04-24 15:41
zhangpeng
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2006-4-9
收藏
得分:0 
总之一句话就是一些死规则用到查一下就行多记记!

2006-04-24 15:43
快速回复:[原创][讨论]C编写的时钟
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028015 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved