c/c++开发分享C语言基于EasyX绘制时钟实例为大家分享了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; }
效果:
以上就是c/c++开发分享C语言基于EasyX绘制时钟的全部内容,希望对大家的学习有所帮助,也希望大家多多支持<计算机技术网(www.ctvol.com)!!>。
需要了解更多c/c++开发分享C语言基于EasyX绘制时钟,都可以关注C/C++技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/c-cdevelopment/1237879.html