網(wǎng)站首頁 編程語言 正文
本文實例為大家分享了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;
}
效果:
原文鏈接:https://blog.csdn.net/qq_37076942/article/details/100929981
相關(guān)推薦
- 2022-03-06 Android系統(tǒng)服務(wù)概覽_Android
- 2022-09-13 Android實現(xiàn)屏幕旋轉(zhuǎn)四個方向準(zhǔn)確監(jiān)聽_Android
- 2022-05-01 docker鏡像與傳統(tǒng)vm虛擬機區(qū)別及分析_docker
- 2021-12-16 jquery+swiper組件實現(xiàn)時間軸滑動年份tab切換效果_jquery
- 2022-01-19 解決form表單reset()報錯,$(...)[0].reset is not a functio
- 2022-08-15 前端寫代碼的時候,不滿足條件程序停止執(zhí)行下面的程序,并彈窗提示
- 2022-12-27 os_object_release?Crash?排查記錄分析_匯編語言
- 2022-09-27 Python?Matplotlib繪制扇形圖標(biāo)簽重疊問題解決過程_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支