C++ easyx时钟(不同时区)

#include<graphics.h>
#include<conio.h>
#include<math.h>
#define WIDTH 600
#define HEIGHT 600
#define PI 3.14159
#define BLANK 30

class initGraph {
    
    
public:
	initGraph(int w, int h)
	{
    
    
		initgraph(w, h);
		BeginBatchDraw();
	}
	~initGraph()
	{
    
    
		EndBatchDraw();
		closegraph();
	}
};

int centX, centY;//表的圆心
int clockRadius;

double secondLength;
int secondEndX, secondEndY;
double secondAngle;

double minuteLength;
int minuteEndX, minuteEndY;
double minuteAngle;

double hourLength;
int hourEndX, hourEndY;
double hourAngle;

int centX1, centY1;
int clockRadius1;

double secondLength1;
int secondEndX1, secondEndY1;
double secondAngle1;

double minuteLength1;
int minuteEndX1, minuteEndY1;
double minuteAngle1;

double hourLength1;
int hourEndX1, hourEndY1;
double hourAngle1;

void startup()
{
    
    
	centX = WIDTH / 2;
	centY = HEIGHT / 2;
	clockRadius = WIDTH / 2 - BLANK;
	secondLength = clockRadius * 4 / 5;
	minuteLength = secondLength * 2 / 3;
	hourLength = minuteLength * 1 / 2;

	centX1 = WIDTH + WIDTH / 2;
	centY1 = HEIGHT / 2;
	clockRadius1 = WIDTH / 2 - BLANK;
	secondLength1 = clockRadius * 4 / 5;
	minuteLength1 = secondLength * 2 / 3;
	hourLength1 = minuteLength * 1 / 2;
}

void drawBeiJingClock()
{
    
    
	cleardevice();//清屏
	for (int i = 0; i < 60; i++) {
    
    
		int x = centX + int(WIDTH / 2.3 * sin(PI * 2 * i / 60));
		int y = centY + int(WIDTH / 2.3 * cos(PI * 2 * i / 60));
		if (i % 15 == 0) {
    
    
			bar(x - 5, y - 5, x + 5, y + 5);
		}
		else if (i % 5 == 0) {
    
    //per quarter
			setcolor(GREEN);
			circle(x, y, 3);
			
		}
		else {
    
    
			putpixel(x, y, WHITE);//per 5 minutes
		}
	}
	settextcolor(GREEN);
	TCHAR s[] = _T("Local Time");
	outtextxy(centX - 30, centY + WIDTH / 6, s);
	setlinestyle(PS_SOLID, 2);
	setcolor(WHITE);
	circle(centX, centY, clockRadius);
	line(centX, centY, secondEndX, secondEndY);

	setlinestyle(PS_SOLID, 4);
	setcolor(BLUE);
	line(centX, centY, minuteEndX, minuteEndY);

	setlinestyle(PS_SOLID, 8);
	setcolor(YELLOW);
	line(centX, centY, hourEndX, hourEndY);


}
void drawToKoyoClock()
{
    
    
	for (int i = 0; i < 60; i++) {
    
    
		int x = centX1 + int(WIDTH / 2.3 * sin(PI * 2 * i / 60));
		int y = centY1 + int(WIDTH / 2.3 * cos(PI * 2 * i / 60));
		if (i % 15 == 0) {
    
    
			bar(x - 5, y - 5, x + 5, y + 5);
		}
		else if (i % 5 == 0) {
    
    
			setcolor(YELLOW);//quarter
			circle(x, y, 3);
		}
		else {
    
    
			putpixel(x, y, WHITE);//per 5 minutes
		}
	}
	settextcolor(GREEN);
	TCHAR s[] = _T("Tokoyo Time");
	outtextxy(centX1 - 30, centY1 + WIDTH / 6, s);
	setlinestyle(PS_SOLID, 2);
	setcolor(WHITE);
	circle(centX1, centY1, clockRadius1);
	line(centX1, centY1, secondEndX1, secondEndY1);

	setlinestyle(PS_SOLID, 4);
	setcolor(GREEN);
	line(centX1, centY1, minuteEndX1, minuteEndY1);

	setlinestyle(PS_SOLID, 8);
	setcolor(RED);
	line(centX1, centY1, hourEndX1, hourEndY1);

	FlushBatchDraw();//刷新缓冲,产生屏幕效果
}
void updateBeiJingClock()
{
    
    
	SYSTEMTIME ti;
	GetLocalTime(&ti);
	secondAngle = ti.wSecond * 2 * PI / 60;
	secondEndX = centX + secondLength * sin(secondAngle);
	secondEndY = centY - secondLength * cos(secondAngle);

	minuteAngle = ti.wMinute * 2 * PI / 60;
	minuteEndX = centX + minuteLength * sin(minuteAngle);
	minuteEndY = centY - minuteLength * cos(minuteAngle);

	hourAngle = ti.wHour * 2 * PI / 12;
	hourEndX = centX + hourLength * sin(hourAngle);
	hourEndY = centY - hourLength * cos(hourAngle);
}
void updateToKoyoClock()
{
    
    
	SYSTEMTIME ti;
	GetLocalTime(&ti);
	secondAngle1 = ti.wSecond * 2 * PI / 60;
	secondEndX1 = centX1 + secondLength1 * sin(secondAngle1);
	secondEndY1 = centY1 - secondLength1 * cos(secondAngle1);

	minuteAngle1 = ti.wMinute * 2 * PI / 60;
	minuteEndX1 = centX1 + minuteLength1 * sin(minuteAngle1);
	minuteEndY1 = centY1 - minuteLength1 * cos(minuteAngle1);

	hourAngle1 = (ti.wHour + 1) * 2 * PI / 12;
	hourEndX1 = centX1 + hourLength1 * sin(hourAngle1);
	hourEndY1 = centY1 - hourLength1 * cos(hourAngle1);
}
int main()
{
    
    
	initGraph graph(WIDTH * 2, HEIGHT);
	startup();

	while (1)
	{
    
    
		updateBeiJingClock();
		updateToKoyoClock();
		drawBeiJingClock();
		drawToKoyoClock();
		Sleep(1000);
	}
}

猜你喜欢

转载自blog.csdn.net/m0_45311187/article/details/120888361