c语言简谐运动1

上传人:夏** 文档编号:498568437 上传时间:2023-05-03 格式:DOCX 页数:18 大小:17.45KB
返回 下载 相关 举报
c语言简谐运动1_第1页
第1页 / 共18页
c语言简谐运动1_第2页
第2页 / 共18页
c语言简谐运动1_第3页
第3页 / 共18页
c语言简谐运动1_第4页
第4页 / 共18页
c语言简谐运动1_第5页
第5页 / 共18页
点击查看更多>>
资源描述

《c语言简谐运动1》由会员分享,可在线阅读,更多相关《c语言简谐运动1(18页珍藏版)》请在金锄头文库上搜索。

1、使用前在 TC 目录下输入以下两个命令BGIOBJ EGAVGA和TLIB LIBGRAPHICS.LIB+EGAVGA#include stdio.h#include stdlib.h#include graphics.h#include conio.h#include stdlib.h#include math.h#define GAIN 10#include time.h/*增益*/*图形初始化*/*输入处理函数*/*合成处理过程*/#define PI3.14159265void initial(void);void userinput(void);void synthesize(vo

2、id);void welcomegui(void); /*开始页面*/float a1 = 1,w1 = 1,f1 = 0; /*两振动的参数*/float a2 = 1,w2 = 1,f2 = 0;int main(void)welcomegui();return 0;void initial(void)char s50;setbkcolor(RED); /*设置背景色为红色*/setlinestyle(SOLID_LINE,0,THICK_WIDTH); /*设置 直线的风格,粗线*/cleardevice(); /*清屏*/*画最外围的边框*/line(10,10,629,10);lin

3、e (629“ IP 629, 469; line (629“ 462 10, 469; line (10, 469m冈泮画冈SI line (40, 309 4509 30: line (45* 309 4509 400)- line (45* 4009 409 400)- line (409 4009 409 30:sprintf (y SYNTHESIZED BEL0W3- outtextxy(70“ 40“ s)- sprintf(0、THE X13- outtextxy(70“160“ s)八 sprintf(sTHE X23 outtextxy(70“ 280“ s)八 X勞xla

4、觎冈兰毬& line (470, 30“ 609, 30: line (609, 30“ 609,130)- line(609,130“470,130)-line(470,130,470,30);settextstyle(DEFAULT_FONT,HORIZ_DIR,1);sprintf(s,Dynamic);outtextxy(480,40,s);sprintf(s,Information);outtextxy(480,50,s);sprintf(s,of x1:);outtextxy(480,60,s);sprintf(s,A1=%.2f,W1=%.2f,a1,w1);outtextxy(

5、480,70,s);sprintf(s,f1=%.2f,f1);outtextxy(480,80,s);/*函数X2信息区域初始化*/line(470,180,609,180);line(609,180,609,280);line(609,280,470,280);line(470,280,470,180);sprintf(s,Dynamic);outtextxy(480,190,s);sprintf(s,Information);outtextxy(480,200,s);sprintf(s,of X2:);outtextxy(480,210,s);sprintf(s,A2=%.2f,W2=%

6、.2f,a2,w2);outtextxy(480,220,s);sprintf(s,f2=%.2f,f2);outtextxy(480,230,s);/*合成图形信息区初始化*/line(470,300,609,300);line(609,300,609,400);line(609,400,470,400);line(470,400,470,300);sprintf(s,Dynamic);outtextxy(480,310,s);sprintf(s,Information);outtextxy(480,320,s);sprintf(s,of SX:);outtextxy(480,330,s);

7、setlinestyle(SOLID_LINE,0,NORM_WIDTH); /*设置直接风格为细线*/*合成函数的坐标轴*/line(60,90,430,90);line(60,40,60,140);line(425,85,430,90); /*画坐标箭头*/line(430,90,425,95);line(55,45,60,40);line(60,40,65,45);sprintf(s,SX); /*坐标名称*/ outtextxy(43,55,s);sprintf(s,t);outtextxy(425,105,s);sprintf(s,0); /*坐标原点*/ outtextxy(50,

8、90,s);/*X1的坐标轴*/line(60,210,430,210); line(60,160,60,260);line(425,205,430,210); /*画坐标箭头*/ line(430,210,425,215);line(55,165,60,160);line(60,160,65,165);sprintf(s,X1); /*坐标名称*/outtextxy(43,175,s);sprintf(s,t);outtextxy(425,225,s);sprintf(s,0); /*坐标原点*/outtextxy(50,210,s);/*X2的坐标轴*/line(60,330,430,33

9、0);line(60,280,60,380);line(425,325,430,330); /*画坐标箭头*/line(430,330,425,335);line(55,285,60,280);line(60,280,65,285);sprintf(s,X2);/*坐标名称*/outtextxy(43,295,s);sprintf(s,t);outtextxy(425,345,s);sprintf(s,0); /*坐标原点*/outtextxy(50,330,s);void userinput(void)/*输入XI的参数*/printf(nnnttX1 = A1 * COS(W1 * t +

10、 f1); printf(nttPlease input the parameters for X1);printf(nttA1 = );scanf(%f,&a1);printf(nttW1 = );scanf(%f,&w1);printf(nttf1 = ); scanf(%f,&f1);/*输入X2的参数*/printf(nnttX2 = A2 * COS(W2 * t + f2); printf(nttPlease input the parameters for X2);printf(nttA2 = );scanf(%f,&a2);printf(nttW2 = );scanf(%f,&

11、w2);printf(nttf2 = );scanf(%f,&f2);to theprintf(ttPress any key to returnWelcome GUI);getch();/*等待任意键*/welcomegui();void synthesize(void) /*合成处理函数*/ int i = 0;float y1,y2;float sy;char s40;/*屏幕初始化*/int gdriver,gmode;gdriver = DETECT;registerbgidriver(EGAVGA_driver);/* 注initgraph(&gdriver, &gmode,);意

12、此处的第三个参数*/initial(); /*初始化图形*/ setfillstyle(SOLID_FILL,BLACK); sprintf(s,Press any key to begin!); outtextxy(50,420,s);w1 = w1/10;w2 = w2/10;y1 = a1 * cos(w1*PI*i + f1);y2 = a2 * cos(w2*PI*i + f2);y1 = y1 * GAIN;y2 = y2 * GAIN;sy = y1 + y2;getch();/*任意键开始*/*开始画线*/while(i360)setcolor(3);setcolor(2);i

13、+;/*画XI的线*/moveto(60+i-1,y1+210);y1 =GAIN * a1 * cos(w1*i + f1); lineto(60+i,y1+210);/*X1的动态信息显示*/bar(480,90,600,110);sprintf(s,X1 = -%f,y1/GAIN); outtextxy(480,90,s);sprintf(s,t1 = %d,i);outtextxy(480,100,s);/*画X2的线*/moveto(60+i-1,y2+330);y2 =GAIN * a2 * cos(w2*i + f2); lineto(60+i,y2+330);/*X2的动态信

14、息显示*/bar(480,240,600,260);sprintf(s,X2 = -%f,y2/GAIN);outtextxy(480,240,s);sprintf(s,t2 = %d,i);outtextxy(480,250,s);/*画合成曲线*/seccolor(4);moveto(60+i-1,sy+90);sy =y1 + y2;lineto(60 + i, sy+90);/*合成曲线动态信息显示*/bar(480,340,600,360);sprintf(s,SX = -%f,y1/GAIN+y2/GAIN);outtextxy(480,340,s);sprintf(s,t2 = %d,i);outtextxy(480,350,s);delay(2000); /*为看清过程,中间有延迟*/bar(50,410,250,440);/*此句将前的任意键开始的说明擦除*/sprintf(s,Press any key to return to the wel

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号