20220422基于EasyX下的建议钟表(圆盘带刻钟)代码


///
// 程序名称:钟表模拟程序(表针形式)
/2022.04.13///
///需求:圆盘时钟 

#include <stdio.h>

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

#define PI 3.1415926


void yuanpan(){

	//表盘
	fillcircle(320, 240, 160);    //320*240
	outtextxy(296, 310, _T("Daybreak。"));   //指定位置输出字符

	//刻度
	setfillcolor(BLACK);

	int x, y;
	for (int i = 0; i < 60; i++)
	{
		x = 320 + int(145 * sin(PI * 2 * i / 60));
		y = 240 + int(145 * cos(PI * 2 * i / 60));

		if (i % 15 == 0)
			{
				fillrectangle(x - 2, y -2 , x + 2, y + 2);  //长方形的参数
				//fillcircle(x, y, 3);
			}
		else if (i % 5 == 0)
			fillcircle(x, y, 2);
		else 
			fillcircle(x, y, 1);
		
			
	}


}

void  biaozhen(int hour, int minute, int second){

	double a_hour, a_min, a_sec;					// 时、分、秒针的弧度值
	int x_hour, y_hour, x_min, y_min, x_sec, y_sec;	// 时、分、秒针的末端位置

	// 计算时、分、秒针的弧度值
	a_sec = second * 2 * PI / 60;      //2 * PI / 60  一秒的弧度
	a_min = minute * 2 * PI / 60 + a_sec / 60;
	a_hour = hour * 2 * PI / 12 + a_min / 12;

	// 计算时、分、秒针的末端位置
	x_sec = int(120 * sin(a_sec));	y_sec = int(120 * cos(a_sec));
	x_min = int(100 * sin(a_min));	 y_min = int(100 * cos(a_min));
	x_hour = int(70 * sin(a_hour));	y_hour = int(70 * cos(a_hour));

	// 时针(320,240是表中心的坐标)
	setlinestyle(PS_SOLID, 9);
	setlinecolor(WHITE);
	line(320 + x_hour, 240 - y_hour, 320 - x_hour / 7, 240 +y_hour / 7);//起始位置

	// 分针
	setlinestyle(PS_SOLID, 6);
	setlinecolor(WHITE);
	line(320 + x_min, 240 - y_min, 320 - x_min / 5, 240 + y_min / 5);

	// 秒针
	setlinestyle(PS_SOLID, 3);
	setlinecolor(WHITE);
	line(320 + x_sec, 240 - y_sec, 320 - x_sec / 3, 240 + y_sec / 3);


}

																	 



//圆盘上的数字

 void shuzi()
 {
	
	 outtextxy(450,235,"3");
	 outtextxy(185,235,"9");
	 outtextxy(315,105,"12");
	 outtextxy(315,360,"6");
	 outtextxy(385,125,"1");
	 outtextxy(250,125,"11");
	 outtextxy(385,340,"5");
	 outtextxy(250,340,"7");
	 outtextxy(430,170,"2");
	 outtextxy(205,170,"10");
	 outtextxy(430,300,"4");
	 outtextxy(205,300,"8");


 }
int main( )
{
	int hour1, minute1, hour2, minute2, hour3, minute3, hour4, minute4;        // 闹钟变量


	initgraph(640, 480);
	cleardevice();
	setfillcolor(BLACK);
	yuanpan();
	setwritemode(R2_XORPEN);  //设置XOR绘图模式,如果没有,会留下幻影

	SYSTEMTIME time;   //定义时间结构体 用来保存当前的时间



	while (1)    
	{

		GetLocalTime(&time);    // API 函数,获取当地的当前系统日期和时间

		shuzi();
		biaozhen(time.wHour, time.wMinute, time.wSecond); //把表针绘制出来
		shuzi();
		
		

		Sleep(1000);          //1000毫秒

		biaozhen(time.wHour, time.wMinute, time.wSecond);      //----
	}

	closegraph();

	return 0;
}

效果图:

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值