easy_x是实现钟表
生活随笔
收集整理的這篇文章主要介紹了
easy_x是实现钟表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#include <graphics.h> // 引用圖形庫頭文件
#include <conio.h>
#include<math.h>//畫面尺寸
#define High 480
#define Width 640
#define PI 3.14159
int main()
{initgraph(Width, High);//初始化畫布int center_x, center_y;//中心坐標center_x = Width / 2;center_y = High / 2;int secondLength;secondLength = Width / 5;int minute_Length;minute_Length = Width / 7;int hour_Length;hour_Length = Width / 9;int secondEnd_x, secondEnd_y;int minute_x, minute_y;int hour_x, hour_y;float secondAngle = 0;//秒針對應轉動的角度float minuteAngle = 0;float hourAngle = 0;setcolor(WHITE);circle(center_x, center_y, Width / 4);SYSTEMTIME ti;BeginBatchDraw();while (1){GetLocalTime(&ti);//得到當前的時間secondAngle = ti.wSecond * 2 * (PI / 60);secondEnd_x = center_x + secondLength*sin(secondAngle);secondEnd_y = center_y - secondLength*cos(secondAngle);minuteAngle = ti.wMinute * 2 * (PI / 60);minute_x = center_x + minute_Length*sin(minuteAngle);minute_y = center_y - minute_Length*cos(minuteAngle);hourAngle = ti.wHour * 2 * (PI / 12);hour_x = center_x + hour_Length*sin(hourAngle);hour_y = center_y - hour_Length*cos(hourAngle);//畫秒針setlinestyle(PS_SOLID, 1);//設置秒針的樣式和寬度setcolor(YELLOW);//秒針的顏色line(center_x, center_y, secondEnd_x, secondEnd_y);//畫分針setlinestyle(PS_SOLID, 2);//設置分針的樣式和寬度setcolor(BLUE);//分針的顏色line(center_x, center_y, minute_x, minute_y);//畫時針setlinestyle(PS_SOLID, 3);//設置時針的樣式和寬度setcolor(RED);//時針的顏色line(center_x, center_y, hour_x, hour_y);FlushBatchDraw();Sleep(1000);//隱藏前一秒的指針setcolor(BLACK);line(center_x, center_y, secondEnd_x, secondEnd_y);line(center_x, center_y, minute_x, minute_y);line(center_x, center_y, hour_x, hour_y);}EndBatchDraw();_getch();closegraph();return 0;
}
總結
以上是生活随笔為你收集整理的easy_x是实现钟表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php四则运算出题器_php 四则运算
- 下一篇: 外部SRAM