实时钟表(Easy-x)

用编程软件绘图真是太有意思了!get到新技能~~

#include<graphics.h>
#include<conio.h>
#include<math.h>

#define High 480
#define Width 640
#define PI 3.1415926

int main()
{
	initgraph(Width,High);			//初始化640*480的画布
	
	int center_x,center_y;			//中心坐标
	center_x=Width/2;
	center_y=High/2;

	int secondLength=Width/5;				//秒针长度
	int minuteLength=secondLength-50;		//分针长度
	int hourLength=minuteLength-20;			//时针长度

	int secondEnd_x,secondEnd_y;	//秒针的终点=中心+秒针长度
	secondEnd_x=center_x+secondLength;
	secondEnd_y=center_y;

	int minuteEnd_x,minuteEnd_y;	//分针的终点
	minuteEnd_x=center_x+minuteLength;
	minuteEnd_y=center_y;

	int hourEnd_x,hourEnd_y;		//时针的终点
	hourEnd_x=center_x+hourLength;
	hourEnd_y=center_y;

	double secondAngle;			//秒针对应的角度
	double minuteAngle;			//秒针对应的角度
	double hourAngle;			//秒针对应的角度

	SYSTEMTIME ti;				//保存当前时间

	while(1)
	{
		//绘制表盘
		setlinestyle(PS_SOLID,1);
		setcolor(GREEN);
		circle(center_x,center_y,Width/4);
		//画刻度
		int x,y,i;
		for(i=0;i<60;i++)
		{
			x=center_x+int(Width/4.3*sin(PI*2*i/60));
			y=center_y+int(Width/4.3*cos(PI*2*i/60));
			if(i % 15 == 0)
				bar(x-5,y-5,x+5,y+5);
			else if(i % 5 == 0)
				circle(x,y,3);
			else
				putpixel(x,y,WHITE);
		}
		outtextxy(center_x-25,center_y+Width/6,_T("zz时钟"));
		GetLocalTime(&ti);			//获取当前时间
		//秒针角度的变化
		secondAngle=ti.wSecond * 2*PI/60;
		//分针角度的变化
		minuteAngle=ti.wMinute * 2*PI/60+secondAngle/60;
		//时针角度的变化
		hourAngle=ti.wHour * 2*PI/12+minuteAngle/12;
	
		//由角度决定秒针的端点坐标
		secondEnd_x=center_x+secondLength*sin(secondAngle);
		secondEnd_y=center_y-secondLength*cos(secondAngle);
		//由角度决定分针的端点坐标
		minuteEnd_x=center_x+minuteLength*sin(minuteAngle);
		minuteEnd_y=center_y-minuteLength*cos(minuteAngle);
		//由角度决定时针的端点坐标
		hourEnd_x=center_x+hourLength*sin(hourAngle);
		hourEnd_y=center_y-hourLength*cos(hourAngle);

		setlinestyle(PS_SOLID,2);
		setcolor(BLUE);		//画秒针
		line(center_x,center_y,secondEnd_x,secondEnd_y);

		setlinestyle(PS_SOLID,4);
		setcolor(YELLOW);		//画分针
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);

		setlinestyle(PS_SOLID,6);
		setcolor(RED);		//画时针
		line(center_x,center_y,hourEnd_x,hourEnd_y);

		FlushBatchDraw();
		Sleep(10);

		setcolor(BLACK);
		//隐藏前一帧的秒针
		setlinestyle(PS_SOLID,2);
		line(center_x,center_y,secondEnd_x,secondEnd_y);
		//隐藏前一帧的分针
		setlinestyle(PS_SOLID,5);
		line(center_x,center_y,minuteEnd_x,minuteEnd_y);
		//隐藏前一帧的时针
		setlinestyle(PS_SOLID,10);
		line(center_x,center_y,hourEnd_x,hourEnd_y);

	}
	EndBatchDraw();
	getch();
	closegraph();					//关闭图形界面
	return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值