#include<graphics.h>
#include<conio.h>
#include<cmath>
#define High 480
#define Width 640
#define PI 3.1415926
int main()
{
initgraph(Width,High);
int center_x,center_y;
center_x=Width/2;
center_y=High/2;
double second_angle=0;
double hour_angle=0;
double minter_angle=0;
int long_of_second;
long_of_second=Width/5;
int long_of_hour;
long_of_hour=Width/16;
int long_of_minter;
long_of_minter=Width/9;
int second_x,second_y;
second_x=long_of_second+center_x;
second_y=long_of_second+center_y;
int hour_x,hour_y;
hour_x=long_of_hour+center_x;
hour_y=long_of_hour+center_y;
int minter_x,minter_y;
minter_x=long_of_minter+center_x;
minter_y=long_of_minter+center_y;
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, "我的时钟");
GetLocalTime(&ti);
second_angle=ti.wSecond*2*PI/60;
minter_angle=ti.wMinute*2*PI/60;
hour_angle=ti.wHour*2*PI/12;
setlinestyle(PS_SOLID,1);
setcolor(WHITE);
second_x=center_x+long_of_second*sin(second_angle);
second_y=center_y-long_of_second*cos(second_angle);
minter_x=center_x+long_of_minter*sin(minter_angle);
minter_y=center_y-long_of_minter*cos(minter_angle);
hour_x=center_x+long_of_hour*sin(hour_angle);
hour_y=center_y-long_of_hour*cos(hour_angle);
line(center_x,center_y,
second_x,second_y);
setcolor(YELLOW);
setlinestyle(PS_SOLID,2);
line(center_x,center_y,
minter_x,minter_y);
setcolor(GREEN);
setlinestyle(PS_SOLID,4);
line(center_x,center_y,
hour_x,hour_y);
// Sleep(500);
FlushBatchDraw();
setcolor(BLACK);
line(center_x,center_y,
second_x,second_y);
line(center_x,center_y,
minter_x,minter_y);
line(center_x,center_y,
hour_x,hour_y);
}
EndBatchDraw();
getch();
closegraph();
return 0;
}