1.目标要求:
1.实现一个显示图像的时钟
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
/*
实现秒针的转动。定义secondAngle为秒针对应的角度,利用三角几何知识求出秒针的终点坐标:。
secondEnd_ x= center_ x + secondLength * sin(secondAngle);
secondEnd_ y= center_ y - secondLength * cos(secondAngle);
让角度secondAngle循环变化,即实现了秒针转动的动画效果。
*/
void HideCursor(){
//隐藏光标位置 ,这个函数复制代码就行
CONSOLE_CURSOR_INFO cursor_info={
1,0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
}
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;//秒针分针时针计数用的
void startup(){
//【数据初始化】
HideCursor();//不显示光标
IsEnd = 0;
initgraph(Width,High);//展示画布
center_x=Width/2;
center_y=High/2;//中心点信息
second_long= (Width>High)? High/4:Width/4;
second_x=center_x;
second_y = center_y-second_long;//秒针信息
minute_long=second_long*4/5;
minute_x=center_x;
minute_y = center_y