網站首頁 編程語言 正文
本文實例為大家分享了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
相關推薦
- 2022-05-23 Docker容器鏡像相關命令基本介紹與使用_docker
- 2022-05-03 Shell內置命令教程之alias和echo_linux shell
- 2022-05-06 python?selenium中Excel數據維護指南_python
- 2022-12-05 Android實現滑動折疊Header全流程詳解_Android
- 2023-04-08 Swift?HTTP加載請求Loading?Requests教程_Swift
- 2023-02-07 Pytorch中的廣播機制詳解(Broadcast)_python
- 2023-07-14 express token的一個用法
- 2022-06-01 C#文件操作、讀取文件、Debug/Trace類用法_C#教程
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支