How to realize the clock with graphical Interface based on EasyX Library in C language
Today Xiaobian to share with you how the C language based on EasyX library to achieve graphical interface clock related knowledge points, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.
1. Target requirements:
1. Implement a clock that displays an image
two。 The time coincides with the local time
2. C language code: # include / / Library function EasyX needs to be installed in advance. Download # include#include#include#include#include#define High 480#define Width 640max / canvas size # define PI 3.1415ax * SYSTEMTIME ti; GetLocalTime (& ti) on the official website. / / get the local time 1. Ti.wYear 2. Ti.wMonth 3. Ti.wDay 4. Ti.wHour 5. Ti.wMinute 6. Ti.wSecond*//* outtextxy (xmemy, "); / / output text on (xmemy) * / int IsEnd;// whether to end the int center_x,center_y;// midpoint int second_long;// length int second_x,second_y / second position int minute_long;// length int minute_x,minute_y;// minute hand position int hour_long;// length int hour_x,hour_y;// hour hand position int second_num,minute_num,hour_num;// second minute hand hour hand count SYSTEMTIME ti;// defined variable storage system time void startup () {/ / [data initialization] IsEnd = 0; initgraph (Width,High) / / display canvas center_x=Width/2; center_y=High/2;// center point information second_long= (Width > High)? High/4:Width/4; minute_long=second_long*8/9; hour_long=second_long*2/3;// pointer length information GetLocalTime (& ti); / / obtain local time second_num= ti.wSecond;// second hand information second_x=center_x+second_long*sin (2*PI) / 60) * second_num) / / calculate the position of the end point of the second hand second_y=center_y-second_long*cos (2*PI) / 60) * second_num); minute_num= ti.wMinute*5+second_num/12;// minute hand information minute_x=center_x+minute_long*sin (2*PI) / (60,5)) * minute_num) / / calculate the position of the minute hand end point minute_y=center_y-minute_long*cos (2*PI) / (609.5)) * minute_num); hour_num= ti.wHour*5+minute_num/5/12;// hour hand information, calculate hour_x=center_x+hour_long*sin (2*PI) / (129.5)) * hour_num) at 60 degrees centigrade) / / calculate the position of the clockwise end point hour_y=center_y-hour_long*cos (2*PI) / (129.5)) * hour_num);} void show_begin () {/ / [initial page display] BeginBatchDraw (); / / start the batch drawing} void show () {/ / [display screen] int i; setlinestyle (PS_SOLID,2); / / set the linetype to solid and the lineweight to 2 setcolor (DARKGRAY) / / set the fill color to dark gray setfillcolor (DARKGRAY); / / set the fill color to also dark gray fillcircle (center_x,center_y,second_long*21/16); / / draw the outer circle of the dial setcolor (LIGHTGRAY); / / set the color to light gray setfillcolor (LIGHTGRAY); / / set the fill color to light gray fillcircle (center_x,center_y,second_long*6/5); / / fill the dial background for (iDiplo