首先要用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