我是靠谱客的博主 成就芹菜,最近开发中收集的这篇文章主要介绍easyx时钟,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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

#define high 480                     //游戏画面尺寸
#define width 640
#define PI 3.14159

int main()
{
	initgraph(width, high);       //初始化绘图窗口
	int center_x, center_y;        //中心点坐标,钟表中心
	center_x = width / 2;
	center_y = high / 2;
	int secondLength = width / 5;         //秒针长度
	int minuteLength = width / 6;          //分针长度
	int hourLength = width / 7;           //时针长度
	
	int secondEnd_x, secondEnd_y;         //秒针重点
	int minuteEnd_x, minuteEnd_y;          //分针终点
	int hourEnd_x, hourEnd_y;              //时针终点
	float secondAngle;                    //秒针对应角度
	float minuteAngle;                    //分针对应角度
	float hourAngle;                      //时针对应角度

	SYSTEMTIME ti;                        //定义系统时间变量

	BeginBatchDraw();
	while (1)
	{
		//绘制表盘
		setlinestyle(PS_SOLID, 1);
		setcolor(WHITE);
		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("我的时钟"));
		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(YELLOW);
		line(center_x, center_y, secondEnd_x, secondEnd_y);       //画秒针
		setlinestyle(PS_SOLID, 4);
		setcolor(BLUE);
		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, 3);
		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;
}

最后

以上就是成就芹菜为你收集整理的easyx时钟的全部内容,希望文章能够帮你解决easyx时钟所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部