实时时钟 改

#define _CRT_SECURE_NO_WARNINGS 1

#include
#include
#include

#define WIDE 640
#define HIGH 480
#define PI 3.1415926 

void Background(int x,int y,int r)
{
	setcolor(WHITE);
	circle(x, y, r);
	for(float i=0;i<2*PI;i+=PI/6)
	{
		circle(x+sin(i)*(r-5), y-cos(i)*(r-5), 3);
		fillcircle(x + sin(i) * (r - 5), y - cos(i) * (r - 5), 3);
	}
	for (float i = 0; i < 2 * PI; i += PI / 30)
	{
		circle(x + sin(i) * (r - 5), y - cos(i) * (r - 5), 1);
		fillcircle(x + sin(i) * (r - 5), y - cos(i) * (r - 5), 1);
	}
}


int main()
{
	initgraph(WIDE, HIGH);

	int center_x = WIDE / 2;
	int center_y = HIGH / 2;
	int radius = 200;
	float secondangle;
	int secondlengh = 180;
	int secondend_x;
	int secondend_y;

	float minuteangle;
	int minutelengh = 150;
	int minuteend_x;
	int minuteend_y;

	float hourangle;
	int hourlengh = 100;
	int hourend_x;
	int hourend_y;

	SYSTEMTIME ti;

	setlinestyle(PS_SOLID, 2);

	Background(center_x, center_y, radius);

	setlinestyle(PS_SOLID, 2);
	BeginBatchDraw();
	while(1)
	{
		GetLocalTime(&ti);
		secondangle = ti.wSecond * 2 * PI / 60;
		secondend_x = center_x + sin(secondangle)* secondlengh;
		secondend_y = center_y - cos(secondangle)* secondlengh;

		minuteangle = ti.wMinute*1.0 * 2 * PI / 60+ ti.wSecond*1.0/60*PI/6;
		minuteend_x = center_x + sin(minuteangle) * minutelengh;
		minuteend_y = center_y - cos(minuteangle) * minutelengh;

		hourangle = ti.wHour*1.0 * 2 * PI / 12+ ti.wMinute*1.0 / 60 * PI / 6;
		hourend_x = center_x + sin(hourangle) * hourlengh;
		hourend_y = center_y - cos(hourangle) * hourlengh;
		//
		setcolor(WHITE);
		line(center_x, center_y, secondend_x, secondend_y);
		line(center_x, center_y, minuteend_x, minuteend_y);
		line(center_x, center_y, hourend_x, hourend_y);

		FlushBatchDraw();
		Sleep(50);
		//
		setcolor(BLACK);
		line(center_x, center_y, secondend_x, secondend_y);
		line(center_x, center_y, minuteend_x, minuteend_y);
		line(center_x, center_y, hourend_x, hourend_y);
	}
	EndBatchDraw();
	_getch();
	closegraph();
}

1.原先的程序存在时针和分针只会指向整数的问题比如3.59时针指向3而到4.00时针会直接跳到4

如今的时针和分针的角度算法上进行了改进。

2.在表盘的周围上增加了60个小点。

注意:运行这代码需要先下载easyx在vs上。

你可能感兴趣的:(算法,c语言,c#,数据结构,矩阵)