实时时钟

这是最近老师留的作业,反正闲来无事,多花了点时间自己用easy_x的绘图函数写出的,代码如下。(=_=!其实图像的话我直接可以用图片来着)。(o(TヘTo)以后一定要三思而后行啊)
这是运行效果
在这里插入图片描述

#undef UNICODE	
#include<graphics.h>
#include<conio.h>
#include<math.h>
#define PI 3.14159
void showsun()		
{
	int i,d,r,l;
	int px,py;
	int x,y;
	int xp,yp,xpe,ype;
	r = 30;
	d = 20;
	l = 20;
	px = (r+d+l+20)*2;
	py = (r+d+l+20)*2;
	x = px/2;
	y = py/2;
	setcolor(RED);
	setfillcolor(RED);
	fillcircle(x,y,r);
	xp = x;
	xpe = x;
	yp = y - d;
	ype = y - d - l;
	for(i = 0;i<12;i++)
	{
		xp = x + int(cos(PI*2*i/12)*(r+d*1.0));
		yp = y + int(sin(PI*2*i/12)*(r+d*1.0));
		xpe = x + int(cos(PI*2*i/12)*(r+d*1.0+l));
		ype = y + int(sin(PI*2*i/12)*(r+d*1.0+l));
		setlinestyle(PS_SOLID,5);
		setcolor(RED);
		line(xp,yp,xpe,ype);
	}

}
void showmoon( )	
{
	int x,y;
	int r,R;
	int rx,ry;
	int rs;
	int px,py;
	int sl,st,sr,sb;
	int slx,sly,srx,sry,stx,sty,sbx,sby;
	r = 50;
	R = 50; 
	rs = r/3;
	x = 90;
	y = 90;
	rx = x+20;
	ry = y;
	sl = x+r;
	st = y - r/3;
	sr = sl + 2*r/3;
	sb = y + r/3;
	slx = sl;
	sly = st;

	srx = sr;
	sry = sb;

	stx = sr;
	sty = st;

	sbx = sl;
	sby = sb;
	
	setcolor(YELLOW);
	setfillcolor(YELLOW);
	fillcircle(x,y,r);
	setcolor(BLACK);
	setfillcolor(BLACK);
	fillcircle(rx,ry,R);
	setcolor(YELLOW);
	setfillcolor(YELLOW);
	setcolor(YELLOW);
	setfillcolor(YELLOW);
	fillrectangle(sl,st,sr,sb);
	setcolor(BLACK);
	setfillcolor(BLACK);
	fillcircle(slx,sly,rs);
	fillcircle(srx,sry,rs);
	fillcircle(stx,sty,rs);
	fillcircle(sbx,sby,rs);
}
void cleardaynight(int px,int py)
{
	setcolor(BLACK);
	setfillcolor(BLACK);
	fillrectangle(0,0,px,py);
}
void showpm()	
{
	settextcolor(WHITE);
	int x,y;
	x = 50;
	y = 190;
	outtextxy(x,y,"PM");
}
void showam()	
{
	settextcolor(WHITE);
	int x,y;
	x = 50;
	y = 190;
	outtextxy(x,y,"AM");
}
void showmotto()
{
	setcolor(GREEN);
	int x,y;
	x = 700/2-65;
	y = 480/2+130;
	outtextxy(x,y,"GOOD GOOD STUDY");
	x = x +24;
	y = y+20;
	outtextxy(x,y,"DAY DAY UP");
}
void clearampm()
{
	setcolor(BLACK);
	setfillcolor(BLACK);
	int l,r,t,b;
	l = 50;
	r = 90;
	t = 190;
	b = 240;
	bar(l,t,r,b);
}
int main()
{
	
	int W = 700,H = 480;
	int x,y;
	int clearx,cleary;
	int i;
	int xc,yc;
	int hx,hy,hl,mx,my,ml,sx,sy,sl;
	double ha,ma,sa;
	
	initgraph(W,H);
	SYSTEMTIME ti;
	
	x = W/2;
	y = H/2;
	sl = 95;
	ml = 80;
	hl = 70;

	clearx = 180;
	cleary = 180;
	showmotto();
	setlinestyle(PS_SOLID,1);
	setcolor(GREEN);
	circle(x,y,115);
	showmoon();
	setcolor(WHITE);
	setfillcolor(WHITE);

	for(i = 0;i<60;i++)
	{
		xc = x + int(105*sin(PI*2*i/60));
		yc = y + int(105*cos(PI*2*i/60));
		if(i%15 == 0)
			bar(xc-3,yc-3,xc+3,yc+3);
		else if(i%5 ==0)
			circle(xc,yc,2);
		else
			putpixel(xc,yc,WHITE);
	}
	BeginBatchDraw();
	while(1)
	{
		setlinestyle(PS_SOLID,1);
		setcolor(GREEN);
		circle(x,y,45);

		GetLocalTime(&ti);
		ha = ti.wHour*2*PI/12 + ti.wMinute*2*PI/720;
		ma = ti.wMinute*2*PI/60 + ti.wSecond*2*PI/3600;
		sa = ti.wSecond*2*PI/60;

		if(ti.wHour>=6&&ti.wHour<=21)//可以设置日月的显示
		{
			
			cleardaynight(clearx,cleary);
			showsun();
		}
		else
		{
			
			cleardaynight(clearx,cleary);
			showmoon();
			
		}

		if(ti.wHour>=0&&ti.wHour<=12)//设置显示上午下午
		{
			clearampm();
			showam();
		}
		else
		{
				clearampm();
				showpm();
		}
		
		

		hx = x + int (hl*sin(ha));
		hy = y - int (hl*cos(ha));

		mx = x + int (ml*sin(ma));
		my = y - int (ml*cos(ma));

		sx = x + int (sl*sin(sa));
		sy = y - int (sl*cos(sa));

		setlinestyle(PS_SOLID,6);
		setcolor(GREEN);
		line(x,y,hx,hy);
		setlinestyle(PS_SOLID,4);
		setcolor(YELLOW);
		line(x,y,mx,my);
		setlinestyle(PS_SOLID,2);
		setcolor(RED);
		line(x,y,sx,sy);

		FlushBatchDraw(); 
		Sleep(100);

		setcolor(BLACK);
		setlinestyle(PS_SOLID,6);
		line(x,y,hx,hy);
		setlinestyle(PS_SOLID,4);
		line(x,y,mx,my);
		setlinestyle(PS_SOLID,2);
		line(x,y,sx,sy);

	}
	getch();
	closegraph();
	return 0;
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值