1.目标要求:
1.实现一个显示图像的时钟
2.时间与本地时间一致
2.C语言代码:
#include<graphics.h> //需要提前安装库函数EasyX,网上官网下载
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<math.h>
#define High 480
#define Width 640//画布尺寸
#define PI 3.1415
/*
SYSTEMTIME ti;
GetLocalTime(&ti);//获得本地时间
1. ti.wYear
2. ti.wMonth
3. ti.wDay
4. ti.wHour
5. ti.wMinute
6. ti.wSecond
*/
/*
outtextxy(x,y," ");//输出文字在(x,y)上
*/
int IsEnd;//是否结束
int center_x,center_y;//中点
int second_long;//长度
int second_x,second_y;//秒针位置
int minute_long;//长度
int minute_x,minute_y;//分针位置
int hour_long;//长度
int hour_x,hour_y;//时针位置
int second_num,minute_num,hour_num;//秒针分针时针计数用的
SYSTEMTIME ti;//定义变量存储系统时间
void startup(){
//【数据初始化】
IsEnd = 0;
initgraph(Width,High);//展示画布
center_x=Width/2;
center_y=High/2;//中心点信息
second_long= (Width>High)? High/4:Width/4;
minute_long=second_long*8/9;
hour_long=second_long*2/3;//指针长度信息
GetLocalTime(&ti);//获取本地时间
second_num= ti.wSecond;//秒针信息
second_x=center_x+second_long*sin(((2*PI)/60)*second_num);//计算秒针端点位置
second_y=center_y-second_long*cos(((2*PI)/60)*second_num);
minute_num= ti.wMinute*5+second_num/12;