日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

C語言基于EasyX繪制時鐘_C 語言

作者:云淡風輕ing ? 更新時間: 2022-08-06 編程語言

本文實例為大家分享了C語言基于EasyX繪制時鐘的具體代碼,供大家參考,具體內容如下

函數說明:

void line(
?? ?int x1,
?? ?int y1,
?? ?int x2,
?? ?int y2
);

參數

x1
直線的起始點的 x 坐標。

y1
直線的起始點的 y 坐標。

x2
直線的終止點的 x 坐標。

y2
直線的終止點的 y 坐標。

文件素材

源代碼

#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;?? ??? ??? ??? ?//秒針偏轉角度
?? ?float angle_m = 0;?? ??? ??? ??? ?//分針偏轉角度
?? ?float angle_h = 0;?? ??? ??? ??? ?//時針偏轉角度
?? ?BeginBatchDraw();
?? ?outtextxy(width/2-30,10,"我的時鐘");?? ?//輸出文字
?? ?while(1)
?? ?{
?? ??? ?GetLocalTime(&ti);?? ??? ??? ??? ??? ?//獲得系統時間
?? ??? ?//根據系統時間獲取時針、分針、秒針偏轉角度
?? ??? ?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;
}

效果:

原文鏈接:https://blog.csdn.net/qq_37076942/article/details/100929981

欄目分類
最近更新