#include<graphics.h> #include<Windows.h> #include<math.h> //图形屏幕大小 const int SCR_WIDTH = 800; const int SCR_HEIGHT = 800; //中心点 const int CENTER_X = SCR_WIDTH / 2; const int CENTER_Y = SCR_HEIGHT / 2; const int CENTER_R = 15; ege_point Center = { CENTER_X,CENTER_Y }; //时针分针秒针宽度 const int CLOCK_SEC_W = 4; const int CLOCK_MIN_W = 10; const int CLOCK_HOUR_W = 15; //指针长度参数 const int L = SCR_HEIGHT / 4; const float Pi = (float)PI; PIMAGE img; class Time { public: Time() { SYSTEMTIME sys; GetLocalTime(&sys); m_Hour = sys.wHour; m_Minute = sys.wMinute; m_Second = sys.wSecond; m_Millisecond = sys.wMilliseconds; } virtual ~Time() {} int ShowHour(void) { return m_Hour; } int ShowMinute(void) { return m_Minute; } int ShowSecond(void) { return m_Second; } int ShowMillisecond(void) { return m_Millisecond; } private: int m_Hour; int m_Minute; int m_Second; int m_Millisecond; }; ege_point getpos(ege_point center, float rad, float r) { ege_point pos; pos.x = sin(rad) * r + center.x; pos.y = -cos(rad) * r + center.y; return pos; } void Draw(void) { Time Now; putimage(0, 0, SCR_WIDTH, SCR_HEIGHT, img, 0, 0, 1024, 1024, SRCCOPY); ege_enable_aa(true);//开启抗锯齿 setfillcolor(EGEARGB(0xFF, 0x00, 0x00, 0x00)); setcolor(EGEARGB(0xFF, 0x00, 0x00, 0x00)); setlinewidth(CLOCK_HOUR_W); { float h = float(Now.ShowHour() + Now.ShowMinute() / 60.0 + Now.ShowSecond() / 3600.0); ege_point p = getpos(Center, float(2 * h * Pi / 12), L * 1.0f); ege_line(p.x, p.y, Center.x, Center.y); } setlinewidth(CLOCK_MIN_W); { float m = float(Now.ShowMinute() + Now.ShowSecond() / 60.0 + Now.ShowMillisecond() / 60000.0); ege_point p = getpos(Center, float(2 * m * Pi / 60), L * 1.3f); ege_line(p.x, p.y, Center.x, Center.y); } setlinewidth(CLOCK_SEC_W); { float s = float(Now.ShowSecond() + Now.ShowMillisecond() / 1000.0); ege_point p = getpos(Center, float(2 * s * Pi / 60), L * 1.6f); ege_line(p.x, p.y, Center.x, Center.y); } ege_fillellipse(CENTER_X - CENTER_R, CENTER_Y - CENTER_R, 2 * CENTER_R, 2 * CENTER_R); } void mainloop(void) { for (; is_run(); delay_fps(60)) { cleardevice(); Draw(); } } int main(void) { setinitmode(INIT_ANIMATION); initgraph(SCR_WIDTH, SCR_HEIGHT); img = newimage(); getimage(img, "clock.jpg", SCR_WIDTH, SCR_HEIGHT); mainloop(); closegraph(); delimage(img); return 0; }
项目:EGE_动态时钟屏保程序