实时时钟

#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), 2);
		fillcircle(x + sin(i) * (r - 5), y - cos(i) * (r - 5), 2);
	}
}


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 * 2 * PI / 60;
		minuteend_x = center_x + sin(minuteangle) * minutelengh;
		minuteend_y = center_y - cos(minuteangle) * minutelengh;

		hourangle = ti.wHour * 2 * PI / 12;
		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();
}

你可能感兴趣的:(算法,c语言,排序算法,开发语言,数据结构)