制作实时时间的秒针

首先要用VS2017(c++)来进行和easyx图库进行下载网站https://easyx.cn

1.添加头文件

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

2.添加宏变量定义

#define High 480
#define width 640
#define PI 3.14159

3.主函数

using namespace std;
int main ()
{

}

4.初始化画布

initgraph(width, High);

5.计算我们需要的数据

    int center_x, center_y;
	center_x = width / 2;
	center_y = High / 2;
	int s1;
	s1 = width / 5;

6.创建秒针的x,y和必要数据

    int s2x,s2y;

	float secondAngle = 0;

7.创建其他辅助数据

    SYSTEMTIME ti;
	
	BeginBatchDraw();

8.主循环

while(1)
{

}

9.主循环里的代码

        GetLocalTime(&ti);
		secondAngle = ti.wSecond * 2 * PI / 60;

		s2x = center_x + s1 * sin(secondAngle);
		s2y = center_y - s1 * cos(secondAngle);

		setlinestyle(PS_SOLID, 2);
		setcolor(WHITE);
		line(center_x, center_y, s2x, s2y);

		FlushBatchDraw();

		Sleep(1);

		setcolor(BLACK);
		line(center_x, center_y, s2x, s2y);

10.最后看完整代码

​
#include <iostream>
#include <conio.h>
#include <stdio.h>
#include <graphics.h>
#include <math.h>

#define High 480
#define width 640
#define PI 3.14159

using namespace std;
int main()
{
	initgraph(width, High);

	int center_x, center_y;
	center_x = width / 2;
	center_y = High / 2;
	int s1;
	s1 = width / 5;

	int s2x,s2y;

	float secondAngle = 0;

	SYSTEMTIME ti;
	
	BeginBatchDraw();

	while (1)
	{
		GetLocalTime(&ti);
		secondAngle = ti.wSecond * 2 * PI / 60;

		s2x = center_x + s1 * sin(secondAngle);
		s2y = center_y - s1 * cos(secondAngle);

		setlinestyle(PS_SOLID, 2);
		setcolor(WHITE);
		line(center_x, center_y, s2x, s2y);

		FlushBatchDraw();

		Sleep(1);

		setcolor(BLACK);
		line(center_x, center_y, s2x, s2y);

	}

	EndBatchDraw();

	std::cin.get();
	closegraph();

	return 0;
}

​

这个代码涉及的知识很多,需要大家学习easyx图库,和时间的提取

那么如果你也喜欢c/c++那么你可以加入这个群,很自由只要没有骂人话。

群号:1015285728

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值