C語言基于EasyX繪制時鐘
更新時間:2022年06月14日 10:57:36 作者:云淡風(fēng)輕ing
這篇文章主要為大家詳細(xì)介紹了C語言基于EasyX繪制時鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了C語言基于EasyX繪制時鐘的具體代碼,供大家參考,具體內(nèi)容如下
函數(shù)說明:
void line( ?? ?int x1, ?? ?int y1, ?? ?int x2, ?? ?int y2 );
參數(shù)
x1
直線的起始點的 x 坐標(biāo)。y1
直線的起始點的 y 坐標(biāo)。x2
直線的終止點的 x 坐標(biāo)。y2
直線的終止點的 y 坐標(biāo)。
文件素材

源代碼
#include <graphics.h>
#include <conio.h>
#include <math.h>
#define PI 3.1415926
int main()
{
?? ?int high=500;
?? ?int width=500;
?? ?initgraph(width,high);?? ??? ?
?? ?IMAGE img;?? ??? ??? ??? ??? ?
?? ?loadimage(&img,"timg.jpg");?? ??? ?//加載圖片
?? ?putimage(0,0,&img);?? ??? ??? ??? ?//顯示圖片
?? ?SYSTEMTIME ti;
?? ?float angle_s = 0;?? ??? ??? ??? ?//秒針偏轉(zhuǎn)角度
?? ?float angle_m = 0;?? ??? ??? ??? ?//分針偏轉(zhuǎn)角度
?? ?float angle_h = 0;?? ??? ??? ??? ?//時針偏轉(zhuǎn)角度
?? ?BeginBatchDraw();
?? ?outtextxy(width/2-30,10,"我的時鐘");?? ?//輸出文字
?? ?while(1)
?? ?{
?? ??? ?GetLocalTime(&ti);?? ??? ??? ??? ??? ?//獲得系統(tǒng)時間
?? ??? ?//根據(jù)系統(tǒng)時間獲取時針、分針、秒針偏轉(zhuǎn)角度
?? ??? ?angle_s = ti.wSecond*2*PI/60;?? ??? ?
?? ??? ?angle_m = ti.wMinute*2*PI/60;
?? ??? ?angle_h = ti.wHour*2*PI/12;
?? ??? ?//繪制秒針
?? ??? ?setcolor(RED);
?? ??? ?setlinestyle(PS_SOLID,2);
?? ??? ?line(width/2,high/2,width/2+120*sin(angle_s),high/2-120*cos(angle_s));
?? ??? ?setcolor(GREEN);
?? ??? ?//繪制分針
?? ??? ?setlinestyle(PS_SOLID,3);
?? ??? ?line(width/2,high/2,width/2+80*sin(angle_m),high/2-80*cos(angle_m));
?? ??? ?setcolor(BLACK);
?? ??? ?//繪制時針
?? ??? ?setlinestyle(PS_SOLID,4);
?? ??? ?line(width/2,high/2,width/2+50*sin(angle_h),high/2-50*cos(angle_h));
?? ??? ?FlushBatchDraw();
?? ??? ?//Sleep(50);
?? ??? ?//清除前一幀的繪圖
?? ??? ?setcolor(WHITE);
?? ??? ?line(width/2,high/2,width/2+120*sin(angle_s),high/2-120*cos(angle_s));
?? ??? ?line(width/2,high/2,width/2+80*sin(angle_m),high/2-80*cos(angle_m));
?? ??? ?line(width/2,high/2,width/2+50*sin(angle_h),high/2-50*cos(angle_h));
?? ?}
?? ?EndBatchDraw();
?? ?getch();
?? ?closegraph();
?? ?return 0;
}效果:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Linux/C++多線程實例學(xué)習(xí)十字路口車輛調(diào)度
這篇文章主要為大家介紹了Linux/C++多線程實例學(xué)習(xí)十字路口車輛調(diào)度示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
C++?超詳細(xì)分析數(shù)據(jù)結(jié)構(gòu)中的時間復(fù)雜度
時間復(fù)雜度一般指時間復(fù)雜性。?在計算機(jī)科學(xué)中,時間復(fù)雜性,又稱時間復(fù)雜度,算法的時間復(fù)雜度是一個函數(shù),它定性描述該算法的運(yùn)行時間2022-03-03
C++實現(xiàn)LeetCode(107.二叉樹層序遍歷之二)
這篇文章主要介紹了C++實現(xiàn)LeetCode(107.二叉樹層序遍歷之二),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
C++中的static和const的關(guān)鍵字用法詳解
這篇文章主要介紹了C++中的static和const的關(guān)鍵字用法詳解,這是一道經(jīng)常在面試中被問到的知識,本文給大家詳細(xì)介紹下,需要的朋友可以參考下2023-06-06

