C++利用graphics.h的钟表程序

8 篇文章 0 订阅
#include<graphics.h>
#include<iostream>
#include<cmath>
#include<ctime>
#define PI 3.141592653
using namespace std;
int gettime()
{
	return clock()/CLOCKS_PER_SEC;
}
void plottime(int h,int m,int s)
{
	moveto(200,200);
	lineto(200+90*cos((90-s*6)*PI/180),200-90*sin((90-s*6)*PI/180));
	moveto(200,200);
	lineto(200+70*cos((90-m*6)*PI/180),200-70*sin((90-m*6)*PI/180));
	moveto(200,200);
	lineto(200+40*cos((90-h*30)*PI/180),200-40*sin((90-h*30)*PI/180));
}
void plotfigure()
{
	int x,y;
	char str[3];
	circle(200,200,100);
	for(int i=0;i<12;i++)
	{
		x=int(200+100*cos((90-i*30)*PI/180));
		y=int(200-100*sin((90-i*30)*PI/180));
		circle(x,y,3);
		sprintf(str,"%d",i==0?12:i);
		outtextxy(x,y,str);
	}
}
int main()
{
	time_t t;
	int lasttime=0;
	int nowtime=0;
	tm *lotime;
	initgraph(640,480);
	plotfigure();
	t=time(0);
	lotime=localtime(&t);
	plottime(lotime->tm_hour,lotime->tm_min,lotime->tm_sec);
	while(1)
	{
		nowtime=gettime();
		if(nowtime-lasttime>0)
		{
			t=time(0);
			lotime=localtime(&t);
			cleardevice();
			plotfigure();
			plottime(lotime->tm_hour,lotime->tm_min,lotime->tm_sec);
			lasttime=nowtime;
		}	
	}	
	getchar();
	closegraph();
	return 0;
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值