鱼C论坛

 找回密码
 立即注册
查看: 1523|回复: 2

[已解决]想问一个if语句的用法

[复制链接]
发表于 2023-4-4 15:29:27 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
我的想法是定义两个数Bd,H,当350<Bd<450,350<H<450时{a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}
当450=<Bd<550,450=<H<550时{a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}
  1. float simulation()//动力箱
  2. {
  3.         float Bd,H,a,b,L1,L2,L3,B1,H1,hh;


  4.         if(Bd>350 && Bd<450 && H>350 && H<450)
  5.         {a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
  6.         if(Bd>=450&&Bd<=550&&H>=450&&H<=550)
  7.         {a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32

  8.         init_figure();//初始化图像网格
  9.         line(a,b,a,b+L1);
  10.         line(a,b+L1,a+H1,b+L1);
  11.         line(a+H1,b+L1,a+H1,b+L1-L2);
  12.         rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
  13.         line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
  14.         line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
  15.         line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
  16.         line(a,b,a+H1/3,b);
  17.         line(a+H1/4,b,a+H1/4,b-L1/6);
  18.         line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
  19.         line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);


  20.         setrop2(R2_COPYPEN);//当前颜色
  21.         setfillcolor(WHITE);
  22.         setlinecolor(WHITE);
  23.         ;//覆盖原进度条区域
  24.        
  25.         setlinestyle(PS_NULL);//无线条
  26.         //设置文字填充背景为透明
  27.         //计算步骤
  28.        
  29.         EndBatchDraw();//结束缓存区

  30.         return 0;
  31. }
复制代码

这是用到这部分代码的部分

输入Bd和H我用的switch语句
  1.         case 2:
  2.                                         InputBox(s,30,"请输入");
  3.                                         sscanf(s,"%f%f",&Bd,&H);//将输入字符串依次扫描到全局变量里面
  4.                                         simulation();//仿真运行
  5.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  6.                                         break;
复制代码

但是我输入Bd和H的值之后 明明在if语句的范围内 但是却不会出现图形,不知道是哪里出现的问题


下面是完整的代码

  1. #include <graphics.h>              // 引用图形库头文件
  2. #include <conio.h>
  3. #include <stdio.h>
  4. #include <windows.h>                                //用到了定时函数sleep()
  5. #include <math.h>
  6. #include <string.h>
  7. #define PI 3.1416

  8. int r[7][4]={{0,20,130,60},{130,20,260,60},{260,20,390,60},{390,20,520,60},{520,20,650,60},{650,20,780,60},{800,20,890,60}};//三个按钮的二维数组
  9. float Bd,H,q,GA=1;//a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6,//动力箱
  10. //j=400,k=100,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,N5=71,N6=90,N=19,//立柱侧底座
  11. //m=466,n=160,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22;//滑台 有些与动力箱的表达一样但是值不一样(H1)
  12. //按钮判断函数
  13. int button_judge(int x,int y)
  14. {
  15.         if(x>r[0][0] && x<r[0][2] && y>r[0][1] && y<r[0][3])return 1;
  16.         if(x>r[1][0] && x<r[1][2] && y>r[1][1] && y<r[1][3])return 2;
  17.         if(x>r[2][0] && x<r[2][2] && y>r[2][1] && y<r[2][3])return 3;
  18.         if(x>r[3][0] && x<r[3][2] && y>r[3][1] && y<r[3][3])return 4;
  19.         if(x>r[4][0] && x<r[4][2] && y>r[4][1] && y<r[4][3])return 5;
  20.         if(x>r[5][0] && x<r[5][2] && y>r[5][1] && y<r[5][3])return 6;
  21.         if(x>r[6][0] && x<r[6][2] && y>r[6][1] && y<r[6][3])return 7;
  22.         return 0;
  23. }
  24. //初始化图像
  25. void init_figure()
  26. {
  27.         int i;
  28.         setrop2(R2_COPYPEN);//当前颜色
  29.         setlinecolor(BLACK);
  30.         setlinestyle(PS_SOLID);//实线
  31.         //外框线
  32.         //点线
  33.         //水平辅助线
  34.        
  35. }
  36. //仿真运行

  37. float simulation()//动力箱
  38. {
  39.         float Bd,H,a,b,L1,L2,L3,B1,H1,hh;


  40.         if(Bd>350 && Bd<450 && H>350 && H<450)
  41.         {a=196,b=100,L1=32,L2=15,L3=32,B1=32,H1=25,hh=2.6;}//25
  42.         if(Bd>=450&&Bd<=550&&H>=450&&H<=550)
  43.         {a=496,b=172,L1=40,L2=15,L3=32,B1=40,H1=32,hh=2.6;}//32



  44.         init_figure();//初始化图像网格
  45.         line(a,b,a,b+L1);
  46.         line(a,b+L1,a+H1,b+L1);
  47.         line(a+H1,b+L1,a+H1,b+L1-L2);
  48.         rectangle(a+H1,b+L1-L2+2,a+H1+hh,b+L1-2);
  49.         line(a+H1+hh/2,b+L1-L2+2,a+H1+hh/2,b+L1-2);
  50.         line(a+H1,b+L1-L2,a+H1,b+L1-L2-L3/5);
  51.         line(a+H1,b+L1-L2-L3/5,a+H1/3,b);
  52.         line(a,b,a+H1/3,b);
  53.         line(a+H1/4,b,a+H1/4,b-L1/6);
  54.         line(a+H1/4,b-L1/6,a+H1-H1/10,b-L1/6);
  55.         line(a+H1-H1/10,b-L1/6,a+H1-H1/10,b-L1/6+4*L3/5-5*GA);







  56.         setrop2(R2_COPYPEN);//当前颜色
  57.         setfillcolor(WHITE);
  58.         setlinecolor(WHITE);
  59.         ;//覆盖原进度条区域
  60.        
  61.         setlinestyle(PS_NULL);//无线条
  62.         //设置文字填充背景为透明
  63.         //计算步骤
  64.        
  65.         EndBatchDraw();//结束缓存区

  66.         return 0;
  67. }
  68. int hello()
  69. {
  70.         float c,d;
  71.         c=60,d=368.5;
  72.        
  73.         init_figure();//初始化图像网格
  74.         rectangle(c,d,c+11,d+20);
  75.         rectangle(c+11,d,c+49,d+16);
  76.         rectangle(c+49,d,c+60,d+20);
  77.         line(c+6,d-15,c+6,d);
  78.         line(c+54,d,c+54,d-15);
  79.         line(c+11,d-15,c,d-15);
  80.         line(c,d-15,c,d-33);
  81.         line(c,d-33,c+5,d-33);
  82.         line(c+5,d-33,c+6,d-36);
  83.         line(c+49,d-15,c+60,d-15);
  84.         line(c+60,d-15,120,d-33);
  85.         line(c+60,d-33,c+55,d-33);
  86.         line(c+55,d-33,c+54,d-36);
  87.         line(c+54,d-36,c+6,d-36);
  88.         line(c+11,d-15,c+12,d-17);
  89.         line(c+49,d-15,c+48,d-17);
  90.         rectangle(c+12,d-30,c+48,d-17);
  91.         rectangle(c+10,d-268.5,c+50,d-36);
  92.         rectangle(c+10,d-268.5,c+50,d-236);
  93.         line(c+10,d-40.5,c+15,d-40.5);
  94.         line(c+15,d-40.5,c+15,d-48.5);
  95.         line(c+15,d-48.5,c+10,d-53.5);
  96.         line(c+50,d-40.5,c+45,d-40.5);
  97.         line(c+45,d-40.5,c+45,d-40.5);
  98.         line(c+45,d-48.5,c+50,d-53.5);
  99.         rectangle(c+20,d-53.5,c+40,d-40.5);
  100.         rectangle(c+22,d-48.5,c+38,d-40.5);
  101.         line(c+20,d-53.5,c+22,d-48.5);
  102.         line(c+40,d-53.5,c+38,d-48.5);
  103.         rectangle(c+9,d-68.5,c+10,d-58.5);
  104.         rectangle(c+51,d-68.5,c+50,d-58.5);
  105.         rectangle(c+17.5,d-195,c+42.5,d-143);
  106.         rectangle(c+17.5,d-143,c+25,d-101);
  107.         rectangle(c+42.5,d-143,c+35,d-101);
  108.         line(c+20,d-143,c+20,d-101);
  109.         line(c+40,d-143,c+40,d-101);
  110.         rectangle(c+27.5,d-101,c+32.5,d-78.5);
  111.         line(c+25,d-101,c+35,d-101);
  112.         line(c+23,d-101,c+23,d-78.5);
  113.         line(c+23,d-78.5,c+15,d-78.5);
  114.         line(c+15,d-78.5,c+15,d-200.4);
  115.         line(c+15,d-78.5,c+15,d-200.4);
  116.         line(c+15,d-200.4,c+23,d-200.4);
  117.         line(c+23,d-200.4,c+23,d-195);
  118.         line(c+37,d-101,c+37,d-78.5);
  119.         line(c+37,d-78.5,c+45,d-78.5);
  120.         line(c+45,d-78.5,c+45,d-200.4);
  121.         line(c+45,d-200.4,c+37,d-200.4);
  122.         line(c+37,d-200.4,c+37,d-195);
  123.         rectangle(c+17.5,d-196.5,c+23,d-195);
  124.         rectangle(c+42.5,d-196.5,c+37,d-195);
  125.         rectangle(c+23,d-198.5,c+29,d-195);
  126.         rectangle(c+37,d-198.5,c+31,d-195);
  127.         rectangle(c+31,d-195,c+29,d-196.5);
  128.         rectangle(c+24,d-210.4,c+28,d-198.5);
  129.         rectangle(c+36,d-210.4,c+32,d-198.5);
  130.         rectangle(c+25,d-236,c+27,d-210.4);
  131.         rectangle(c+35,d-236,c+33,d-210.4);
  132.         line(c+27,d-220.4,c+33,d-220.4);
  133.         rectangle(c+25,d-108.5,c+35,d-101);
  134.         rectangle(c+25,d-104,c+35,d-101);
  135.         rectangle(c+27,d-110.5,c+33,d-108.5);
  136.         rectangle(c+8,d-163.5,c+12,d-153.5);
  137.         rectangle(c+9,d-208.5,c+10,d-195);
  138.         rectangle(c+51,d-208.5,c+50,d-195);
  139.                
  140.         setrop2(R2_COPYPEN);//当前颜色
  141.         setfillcolor(WHITE);
  142.         setlinecolor(WHITE);
  143.         //覆盖原进度条区域
  144.        
  145.         setlinestyle(PS_NULL);//无线条
  146.         //设置文字填充背景为透明
  147.         //计算步骤
  148.        
  149.         EndBatchDraw();//结束缓存区
  150.        
  151.         return 0;
  152. }
  153. float snake()//立柱以及侧底座
  154. {
  155.         float j,k,B1,H5,H6,N3,N4,B2,B3,H7,H8,H9,H1,N5,N6,N;
  156.         j=400,k=100,B1=40,H5=32.5,H6=200,N3=97,N4=66,B2=60,B3=11,H7=56,H8=21,H9=16,H1=6.5,N5=71,N6=90,N=19;
  157.        
  158.         init_figure();//初始化图像网格
  159.         rectangle(j,k,j+N3,k+H5);
  160.         line(j,k+H5,j-(N5-N4),k+H5+40);
  161.         line(j-(N5-N4),k+H5+40,j-(N5-N4),k+H5+H6);
  162.         line(j-(N5-N4),k+H5+H6,j-(N5-N4)+N5,k+H5+H6);
  163.     line(j-(N5-N4)+N5,k+H5+H6,j-(N5-N4)+N5,k+H5);
  164.         rectangle(j,k+H5+H6-15,j+18,k+H5+H6-5);
  165.         rectangle(j+30,k+H5+H6-15,j+48,k+H5+H6-5);//立柱

  166.         rectangle(j-(N5-N4)-N,k+H5+H6,j-(N5-N4)-N+N6,k+H5+H6+H7);
  167.         line(j-(N5-N4)-N,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4);
  168.         line(j-(N5-N4)-N+(2*N6)/3,k+H5+H6+H7-4,j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6);
  169.         line(j-(N5-N4)-N+(2*N6)/3+2,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6);
  170.         line(j-(N5-N4)-N+(2*N6)/3+10,k+H5+H6+H7-6,j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4);
  171.         line(j-(N5-N4)-N+(2*N6)/3+12,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4);
  172.         line(j-(N5-N4)-N+N6-4,k+H5+H6+H7-4,j-(N5-N4)-N+N6-4,k+H5+H6+H7-4-H7/4);
  173.         rectangle(j-(N5-N4)-N+N6-8,k+H5+H6+H7-4-H7/2,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/4);
  174.         rectangle(j-(N5-N4)-N+N6-4,k+H5+H6+3,j-(N5-N4)-N+N6,k+H5+H6+H7-4-H7/2);
  175.         circle(j-(N5-N4),k+H5+H6+H7/2,4);
  176.         circle(j+N4/3,k+H5+H6/6,4);
  177.         circle(j+(4*N4)/5,k+H5+H6/6,4);
  178.         circle(j+N4/4,k+H5+(5*H6)/6,4);
  179.         circle(j+3*N4/4,k+H5+(5*H6)/6,4);
  180.         rectangle(j-(N5-N4)-N+(2*N6)/3+4,k+H5+H6+H7-3,j-(N5-N4)-N+(2*N6)/3+8,k+H5+H6+H7);


  181.                
  182.         setrop2(R2_COPYPEN);//当前颜色
  183.         setfillcolor(WHITE);
  184.         setlinecolor(WHITE);
  185.         //覆盖原进度条区域
  186.        
  187.         setlinestyle(PS_NULL);//无线条
  188.         //设置文字填充背景为透明
  189.         //计算步骤
  190.        
  191.         EndBatchDraw();//结束缓存区
  192.        
  193.         return 0;

  194. }
  195. float gally()//滑台
  196. {
  197.         float m,n,B=32,L=40,H2=107,H3=63,H4=15.5,N1=28,N2=22; //T25
  198.         m=466,n=160;

  199.        
  200.         init_figure();//初始化图像网格
  201.         rectangle(m,n,m+1.5,n+H3+L+L);
  202.         rectangle(m+1.5,n+10,m+2,n+H3+L+L);
  203.         rectangle(m+2,n+10,m+4,n+H3+L+14);
  204.         rectangle(m+4,n+10,m+2*N2/3+2,n+H3+L+14);
  205.         rectangle(m+6,n+10+(H3+L+4)/2-3,m+2*N2/3,n+(H3+L+4)/2+3);
  206.         line(m+2,n+10,m+2+N2/5,n+10-H4);
  207.         line(m+2+N2/5,n+10-H4,m+2+N2,n+10-H4);
  208.         line(m+2+N2,n+10-H4,m+2+N2,n+10);
  209.         rectangle(m+2+N2,n+10,m+4+N2,n+12);
  210.         rectangle(m+N2-2,n+10,m+N2,n+14+H3+L);
  211.         rectangle(m+N2,n+12,m+2+N1,n+12+H3);
  212.         rectangle(m+N1,n-27.5,m+N1+2,n-11.9);
  213.         rectangle(m+N1-1,n-11.9,m+N1+2,n+10);
  214.         rectangle(m+N1-1,n+10,m+N1,n+12);
  215.         rectangle(m+2+N2-2,n+10+2+H3,m+2+N2,n+14+H3+L);
  216.         rectangle(m+2+N2,n+12+H3+L,m+2+N1,n+14+H3+L);
  217.         line(m+2*N2/3+2,n+14+H3+L,m+2+N2,n+14+H3+L);
  218.         line(m+N1+2,n+10,m+N1+2,n+12);//m+N1+2是滑台右侧横坐标496,n+12是滑台右侧坐标172





  219.                
  220.         setrop2(R2_COPYPEN);//当前颜色
  221.         setfillcolor(WHITE);
  222.         setlinecolor(WHITE);
  223.         //覆盖原进度条区域
  224.        
  225.         setlinestyle(PS_NULL);//无线条
  226.         //设置文字填充背景为透明
  227.         //计算步骤
  228.        
  229.         EndBatchDraw();//结束缓存区

  230.         return 0;
  231. }
  232. float dog()//多轴箱
  233. {
  234.         float w,e,B,H,A0,A,h0,h,L0,L,B1,H1,GA=1;
  235.         w=850,e=400,B=500,H=500,A0=75,A=350,h0=150,h=200,L0=80,L=80,B1=400,H1=320;       
  236.         init_figure();//初始化图像网格
  237.         rectangle(w-B/2,e-H/2,w+B/2,e+H/2);
  238.         line(w-A/2-A0/2-5*GA,e-H/2,w-A/2-A0/2,e-H/2-9*GA);
  239.         line(w-A/2-A0/2,e-H/2-9*GA,w-A/2-A0/2+20*GA,e-H/2-9*GA);
  240.         line(w-A/2-A0/2+20*GA,e-H/2-9*GA,w-A/2-A0/2+25*GA,e-H/2);
  241.         line(w+A/2+A0/2+5*GA,e-H/2,w+A/2+A0/2,e-H/2-9*GA);
  242.         line(w+A/2+A0/2,e-H/2-9*GA,w+A/2+A0/2-20*GA,e-H/2-9*GA);
  243.         line(w+A/2+A0/2-20*GA,e-H/2-9*GA,w+A/2+A0/2-25*GA,e-H/2);
  244.         line(w-A/2,e-H/2,w-A/2,e-H/2-25*GA);
  245.         line(w-A/2,e-H/2-25*GA,w+A/2-5*GA,e-H/2-25*GA);
  246.         line(w+A/2-5*GA,e-H/2-25*GA,w+A/2+5*GA,e-H/2);
  247.         line(w+A/2,e-H/2-10*GA,w-A/2,e-H/2-10*GA);
  248.         line(w-B/2+L0-5*GA,e+H/2,w-B/2+L0,e+H/2+10*GA);
  249.         line(w-B/2+L0,e+H/2+10*GA,w-B/2+L0+L,e+H/2+10*GA);
  250.         line(w-B/2+L0+L,e+H/2+10*GA,w-B/2+L0+L+5*GA,e+H/2);
  251.         line(w+B/2-L0+5*GA,e+H/2,w+B/2-L0,e+H/2+10*GA);
  252.         line(w+B/2-L0,e+H/2+10*GA,w+B/2-L0-L,e+H/2+10*GA);
  253.         line(w+B/2-L0-L,e+H/2+10*GA,w+B/2-L0-L-5*GA,e+H/2);
  254.         rectangle(w-B/2-25*GA,e+H/2-h0-h,w-B/2-10*GA,e+H/2-h0);
  255.         line(w-B/2-10*GA,e+H/2-h0-h,w-B/2,e+H/2-h0-h-5*GA);
  256.         line(w-B/2-10*GA,e+H/2-h0,w-B/2,e+H/2-h0+5*GA);
  257.         rectangle(w+B/2+25*GA,e+H/2-h0-h,w+B/2+10*GA,e+H/2-h0);
  258.         line(w+B/2+10*GA,e+H/2-h0-h,w+B/2,e+H/2-h0-h-5*GA);
  259.         line(w+B/2+10*GA,e+H/2-h0,w+B/2,e+H/2-h0+5*GA);
  260.         setlinestyle(PS_DOT);//点线 可以让画的图变成点线
  261.         rectangle(w+B1/2,e+H/2-H1,w-B1/2,e+H/2);
  262.         rectangle(w+B1/3,e+H/2-(4*H1)/5,w-B1/3,e+H/2-H1/5);


  263.        
  264.         setrop2(R2_COPYPEN);//当前颜色
  265.         setfillcolor(WHITE);
  266.         setlinecolor(WHITE);
  267.         //覆盖原进度条区域
  268.        
  269.         setlinestyle(PS_NULL);//无线条
  270.         //设置文字填充背景为透明
  271.         //计算步骤
  272.        
  273.         EndBatchDraw();//结束缓存区
  274.         ;
  275.         return 0;
  276. }
  277. void pg(float x, float y);
  278. int hhh()//运动
  279. {
  280.        
  281.         int x = 120, y = 140;  //初始坐标
  282.        
  283.         int xSize = 1, ySize = 1;  //每次移动的方向和距离
  284.        
  285.         while (1)
  286.         {
  287.                 BeginBatchDraw();
  288.                 cleardevice();
  289.                 if ( y+100>500)
  290.                 {
  291.                         ySize = 0;
  292.                         Sleep(3000);
  293.                         ySize=-1;
  294.                 }
  295.                 if(y<140)
  296.                 {
  297.                         ySize=0;
  298.                 }
  299.                 y += ySize;  //y移动
  300.                 pg(x, y);
  301.                 FlushBatchDraw();
  302.         }

  303.        
  304.        
  305.        
  306.         EndBatchDraw();//结束缓存区
  307.         _getch();
  308.         closegraph();
  309.         return 0;
  310. }
  311. void pg(float x,float y)
  312. {
  313.        
  314.     cleardevice(); //清屏
  315.         setcolor(BLUE);  
  316.         rectangle(x,y,x+100,y+100);//绘制
  317.         init_figure();
  318.         float w,e;
  319.         w=0,e=0;
  320.        
  321.        
  322.         //初始化图像网格
  323.        
  324.         rectangle(w+600,e+150,w+1100,e+650);
  325.         line(w+635,e+150,w+639,e+142);
  326.         line(w+639,e+142,w+660,e+142);
  327.         line(w+660,e+142,w+664,e+150);

  328.         line(w+1065,e+150,w+1061,e+142);
  329.         line(w+1061,e+142,w+1040,e+142);
  330.         line(w+1040,e+142,w+1036,e+150);

  331.         line(w+675,e+150,w+675,e+125);
  332.         line(w+675,e+125,w+1020,e+125);
  333.         line(w+1020,e+125,w+1030,e+150);
  334.         line(w+675,e+140,w+1025,e+140);

  335.         rectangle(w+590,e+500,w+575,e+300);
  336.         line(w+590,e+500,w+600,e+510);
  337.         line(w+590,e+300,w+600,e+290);

  338.         line(w+680,e+655,w+770,e+655);
  339.         line(w+680,e+655,w+675,e+650);
  340.         line(w+770,e+655,w+775,e+650);
  341.         line(w+1020,e+655,w+930,e+655);
  342.         line(w+1020,e+655,w+1025,e+650);
  343.         line(w+930,e+655,w+925,e+650);

  344.         rectangle(w+1125,e+500,w+1110,e+300);
  345.         line(w+1110,e+300,w+1100,e+290);
  346.         line(w+1110,e+500,w+1100,e+510);

  347.         setlinestyle(PS_DOT);//点线
  348.         rectangle(w+690,e+400,w+1010,e+650);
  349.         rectangle(w+730,e+450,w+960,e+610);
  350.         line(w+670,e+630,w+1030,e+630);//多轴

  351.         setlinestyle(PS_SOLID);//实线

  352.         rectangle(w+1150,e+650,w+1420,e+655);
  353.         line(w+1150,e+650,w+1490,e+650);
  354.         line(w+1150,e+650,w+1150,e+300);
  355.         line(w+1150,e+300,w+1155,e+290);
  356.         line(w+1155,e+290,w+1155,e+150);
  357.         line(w+1155,e+150,w+1240,e+150);
  358.         line(w+1240,e+150,w+1250,e+140);
  359.         rectangle(w+1250,e+125,w+1420,e+140);
  360.         line(w+1420,e+140,w+1425,e+150);
  361.         line(w+1425,e+150,w+1490,e+150);
  362.         line(w+1490,e+150,w+1490,e+650);//外形

  363.         rectangle(w+1183,e+170,w+1241.5,e+630);//左
  364.         rectangle(w+1480,e+630,w+1421.5,e+170);//右
  365.         rectangle(w+1285,e+170,w+1375,e+630);//中
  366.         rectangle(w+1183,e+185,w+1251.5,e+615);//左
  367.         rectangle(w+1480,e+615,w+1411.5,e+185);//右
  368.         setlinestyle(PS_DOT);//点线
  369.         rectangle(w+1264.5,e+300,w+1404.5,e+500);//中

  370.         setlinestyle(PS_SOLID);//实线

  371.        
  372. //猜测
  373.         rectangle(w+1150,e+400,w+1155,e+610);
  374.        
  375.         rectangle(w+1183,e+190,w+1241.5,e+260);//左
  376.         rectangle(w+1480,e+260,w+1421.5,e+190);//右
  377.     line(w+1480,e+350,w+1421.5,e+350);
  378.         line(w+1183,e+350,w+1241.5,e+350);
  379.         line(w+1183,e+420,w+1241.5,e+420);
  380.         line(w+1480,e+420,w+1421.5,e+420);
  381.         line(w+1480,e+510,w+1421.5,e+510);
  382.         line(w+1183,e+510,w+1241.5,e+510);//动力箱法兰

  383.         float m,n;
  384.         m=400,n=100;
  385.        
  386.        
  387.         init_figure();//初始化图像网格
  388.        
  389.        
  390.         rectangle(m+66,n+60,m+67.5,n+205);
  391.         rectangle(m+67.5,n+73.5,m+68,n+205);
  392.         rectangle(m+68,n+73.5,m+70,n+167);
  393.         rectangle(m+70,n+73.5,m+80,n+167);
  394.         rectangle(m+73,n+112,m+77,n+120);
  395.         line(m+68,n+73.5,m+72,n+68.1);
  396.         line(m+72,n+68.1,m+80,n+68.1);
  397.         line(m+80,n+68.1,m+80,n+73.5);
  398.         line(m+68,n+73.5,m+80,n+73.5);
  399.         line(m+72,n+68.1,m+72,n+58.1);
  400.         line(m+72,n+58.1,m+88,n+58.1);
  401.         line(m+88,n+48.1,m+88,n+73.5);
  402.         line(m+74,n+58.1,m+74,n+48.1);
  403.         line(m+74,n+48.1,m+88,n+48.1);
  404.         rectangle(m+82,n+125.5,m+88,n+167.5);
  405.         rectangle(m+82,n+73.5,m+85,n+167.5);
  406.         rectangle(m+85,n+73.5,m+88,n+75.5);
  407.         rectangle(m+95,n+32.5,m+97,n+52.5);
  408.         rectangle(m+94,n+52.5,m+97,n+73.5);
  409.         rectangle(m+94,n+73.5,m+95,n+75.5);
  410.         rectangle(m+85,n+75.5,m+97,n+125.5);

  411.         float c,d;
  412.         c=60,d=368.5;
  413.        
  414.         init_figure();//初始化图像网格
  415.         rectangle(c,d,c+11,d+20);
  416.         rectangle(c+11,d,c+49,d+16);
  417.         rectangle(c+49,d,c+60,d+20);
  418.         line(c+6,d-15,c+6,d);
  419.         line(c+54,d,c+54,d-15);
  420.         line(c+11,d-15,c,d-15);
  421.         line(c,d-15,c,d-33);
  422.         line(c,d-33,c+5,d-33);
  423.         line(c+5,d-33,c+6,d-36);
  424.         line(c+49,d-15,c+60,d-15);
  425.         line(c+60,d-15,120,d-33);
  426.         line(c+60,d-33,c+55,d-33);
  427.         line(c+55,d-33,c+54,d-36);
  428.         line(c+54,d-36,c+6,d-36);
  429.         line(c+11,d-15,c+12,d-17);
  430.         line(c+49,d-15,c+48,d-17);
  431.         rectangle(c+12,d-30,c+48,d-17);
  432.         rectangle(c+10,d-268.5,c+50,d-36);
  433.         rectangle(c+10,d-268.5,c+50,d-236);
  434.         line(c+10,d-40.5,c+15,d-40.5);
  435.         line(c+15,d-40.5,c+15,d-48.5);
  436.         line(c+15,d-48.5,c+10,d-53.5);
  437.         line(c+50,d-40.5,c+45,d-40.5);
  438.         line(c+45,d-40.5,c+45,d-40.5);
  439.         line(c+45,d-48.5,c+50,d-53.5);
  440.         rectangle(c+20,d-53.5,c+40,d-40.5);
  441.         rectangle(c+22,d-48.5,c+38,d-40.5);
  442.         line(c+20,d-53.5,c+22,d-48.5);
  443.         line(c+40,d-53.5,c+38,d-48.5);
  444.         rectangle(c+9,d-68.5,c+10,d-58.5);
  445.         rectangle(c+51,d-68.5,c+50,d-58.5);
  446.         rectangle(c+17.5,d-195,c+42.5,d-143);
  447.         rectangle(c+17.5,d-143,c+25,d-101);
  448.         rectangle(c+42.5,d-143,c+35,d-101);
  449.         line(c+20,d-143,c+20,d-101);
  450.         line(c+40,d-143,c+40,d-101);
  451.         rectangle(c+27.5,d-101,c+32.5,d-78.5);
  452.         line(c+25,d-101,c+35,d-101);
  453.         line(c+23,d-101,c+23,d-78.5);
  454.         line(c+23,d-78.5,c+15,d-78.5);
  455.         line(c+15,d-78.5,c+15,d-200.4);
  456.         line(c+15,d-78.5,c+15,d-200.4);
  457.         line(c+15,d-200.4,c+23,d-200.4);
  458.         line(c+23,d-200.4,c+23,d-195);
  459.         line(c+37,d-101,c+37,d-78.5);
  460.         line(c+37,d-78.5,c+45,d-78.5);
  461.         line(c+45,d-78.5,c+45,d-200.4);
  462.         line(c+45,d-200.4,c+37,d-200.4);
  463.         line(c+37,d-200.4,c+37,d-195);
  464.         rectangle(c+17.5,d-196.5,c+23,d-195);
  465.         rectangle(c+42.5,d-196.5,c+37,d-195);
  466.         rectangle(c+23,d-198.5,c+29,d-195);
  467.         rectangle(c+37,d-198.5,c+31,d-195);
  468.         rectangle(c+31,d-195,c+29,d-196.5);
  469.         rectangle(c+24,d-210.4,c+28,d-198.5);
  470.         rectangle(c+36,d-210.4,c+32,d-198.5);
  471.         rectangle(c+25,d-236,c+27,d-210.4);
  472.         rectangle(c+35,d-236,c+33,d-210.4);
  473.         line(c+27,d-220.4,c+33,d-220.4);
  474.         rectangle(c+25,d-108.5,c+35,d-101);
  475.         rectangle(c+25,d-104,c+35,d-101);
  476.         rectangle(c+27,d-110.5,c+33,d-108.5);
  477.         rectangle(c+8,d-163.5,c+12,d-153.5);
  478.         rectangle(c+9,d-208.5,c+10,d-195);
  479.         rectangle(c+51,d-208.5,c+50,d-195);
  480.         float j,k;
  481.         j=400,k=100;
  482.        
  483.        
  484.         init_figure();//初始化图像网格
  485. //h5
  486.         rectangle(j,k,j+97,k+32.5);
  487. //斜线
  488.         line(j,k+32.5,j-5,k+92.5);
  489. //h6 h2 h3 h4
  490.         line(j-5,k+232.5,j-5,k+92.5);
  491. //n5
  492.         line(j-5,k+232.5,j+66,k+232.5);
  493.         line(j+66,k+32.5,j+66,k+232.5);
  494.         rectangle(j,k+215,j+20,k+228);
  495.         rectangle(j+35,k+215,j+55,k+228);

  496.         float p,q;
  497.         p=400,q=100;//侧底座数据
  498.         line(p-5,q+232.5,p-5,q+288.5);
  499.         line(p-5,q+288.5,p+66,q+288.5);
  500.         line(p-5,q+284.5,p+26,q+284.5);
  501.         line(p-5,q+232.5,p+66,q+232.5);
  502.         line(p+26,q+284.5,p+28,q+282.5);
  503.         line(p+28,q+282.5,p+35,q+282.5);
  504.         line(p+35,q+282.5,p+37,q+284.5);
  505.         line(p+37,q+284.5,p+62,q+284.5);
  506.         rectangle(p+29,q+286.5,p+34,q+288.5);
  507.         line(p+62,q+284.5,p+62,q+264.5);
  508.         line(p+66,q+288.5,p+66,q+264.5);
  509.         line(p+66,q+264.5,p+60,q+264.5);
  510.         line(p+60,q+264.5,p+60,q+258.5);
  511.         line(p+60,q+258.5,p+66,q+258.5);
  512.         line(p+66,q+258.5,p+66,q+232.5);
  513.         rectangle(p+62,q+235.5,p+66,q+258.5);
  514.         circle(p,q+260,2);

  515.         init_figure();


  516.        
  517.         Sleep(10);
  518. }



  519. int main()
  520. {
  521.         int i,event=0;
  522.         char s[30];//输入字符串变量
  523.         short win_width,win_height;//定义窗口的宽度和高度
  524.         win_width = 1640;win_height = 760;
  525.         initgraph(win_width,win_height);//初始化窗口(黑屏)
  526.         for(i=0;i<256;i+=5)
  527.         {
  528.                 setbkcolor(RGB(i,i,i));//设置背景色,原来默认黑色
  529.                 cleardevice();//清屏(取决于背景色)
  530.                 Sleep(30);//延时30ms
  531.         }
  532.         RECT R1={r[0][0],r[0][1],r[0][2],r[0][3]};
  533.         RECT R2={r[1][0],r[1][1],r[1][2],r[1][3]};
  534.         RECT R3={r[2][0],r[2][1],r[2][2],r[2][3]};
  535.         RECT R4={r[3][0],r[3][1],r[3][2],r[3][3]};
  536.         RECT R5={r[4][0],r[4][1],r[4][2],r[4][3]};
  537.         RECT R6={r[5][0],r[5][1],r[5][2],r[5][3]};
  538.         RECT R7={r[6][0],r[6][1],r[6][2],r[6][3]};


  539.         LOGFONT f;//字体样式指针
  540.         gettextstyle(&f);                                        //获取字体样式
  541.         _tcscpy(f.lfFaceName,_T("宋体"));        //设置字体为宋体
  542.         f.lfQuality = ANTIALIASED_QUALITY;    // 设置输出效果为抗锯齿  
  543.         settextstyle(&f);                     // 设置字体样式
  544.         settextcolor(BLACK);                                //BLACK在graphic.h头文件里面被定义为黑色的颜色常量
  545.         drawtext("11",&R1,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R1内输入文字,水平居中,垂直居中,单行显示
  546.         drawtext("11",&R2,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R2内输入文字,水平居中,垂直居中,单行显示
  547.         drawtext("立柱",&R3,DT_CENTER | DT_VCENTER | DT_SINGLELINE);//在矩形区域R3内输入文字,水平居中,垂直居中,单行显示
  548.         drawtext("滑台",&R4,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  549.         drawtext("多轴箱",&R5,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  550.         drawtext("运动",&R6,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  551.         drawtext("退出",&R7,DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  552.         setlinecolor(BLUE);
  553.         rectangle(r[0][0],r[0][1],r[0][2],r[0][3]);
  554.         rectangle(r[1][0],r[1][1],r[1][2],r[1][3]);
  555.         rectangle(r[2][0],r[2][1],r[2][2],r[2][3]);
  556.         rectangle(r[3][0],r[3][1],r[3][2],r[3][3]);
  557.         rectangle(r[4][0],r[4][1],r[4][2],r[4][3]);
  558.         rectangle(r[5][0],r[5][1],r[5][2],r[5][3]);
  559.         rectangle(r[6][0],r[6][1],r[6][2],r[6][3]);
  560.         MOUSEMSG m;//鼠标指针
  561.        
  562.         while(true)
  563.         {
  564.                 m = GetMouseMsg();//获取一条鼠标消息

  565.                 switch(m.uMsg)
  566.                 {
  567.                         case WM_MOUSEMOVE:
  568.                                 setrop2(R2_XORPEN);
  569.                                 setlinecolor(LIGHTCYAN);//线条颜色为亮青色
  570.                                 setlinestyle(PS_SOLID, 3);//设置画线样式为实现,10磅
  571.                                 setfillcolor(RED);//填充颜色为白色
  572.                                 if(button_judge(m.x,m.y)!=0)
  573.                                 {
  574.                                         if(event != button_judge(m.x,m.y))
  575.                                         {
  576.                                                 event = button_judge(m.x,m.y);//记录这一次触发的按钮
  577.                                                 fillrectangle(r[event-1][0],r[event-1][1],r[event-1][2],r[event-1][3]);//有框填充矩形(X1,Y1,X2,Y2)
  578.                                         }
  579.                                 }
  580.                                 else
  581.                                 {
  582.                                         if(event!=0)//上次触发的按钮未被修正为原来的颜色
  583.                                         {
  584.                                                 fillrectangle(r[event-1][0],r[event-1][1],r[event-1][2],r[event-1][3]);//两次同或为原来颜色
  585.                                                 event = 0;
  586.                                         }
  587.                                 }
  588.                                 break;
  589.                         case WM_LBUTTONDOWN:
  590.                                 setrop2(R2_NOTXORPEN);//二元光栅——NOT(屏幕颜色 XOR 当前颜色)
  591.                                 for(i=0;i<=10;i++)
  592.                                 {
  593.                                         setlinecolor(RGB(25*i,25*i,25*i));//设置圆颜色
  594.                                         circle(m.x,m.y,2*i);
  595.                                         Sleep(20);//停顿30ms
  596.                                         circle(m.x,m.y,2*i);//抹去刚刚画的圆
  597.                                 }
  598.                                 //按照按钮判断左键单击后的操作
  599.                                 switch(button_judge(m.x,m.y))
  600.                                 {
  601.                                         //复原按钮原型
  602.                                 case 1:
  603.                        
  604.                                         hello();//将输入字符串依次扫描到全局变量里面
  605.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  606.                                         break;
  607.                                 case 2:
  608.                                         InputBox(s,30,"请输入");
  609.                                         sscanf(s,"%f%f",&Bd,&H);//将输入字符串依次扫描到全局变量里面
  610.                                         simulation();//仿真运行
  611.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  612.                                         break;
  613.                                 case 3:
  614.                                         snake();//仿真运行
  615.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  616.                                         break;
  617.                                 case 4:
  618.                                         gally();//仿真运行
  619.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  620.                                         break;
  621.                                 case 5:
  622.                                         dog();//仿真运行
  623.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  624.                                         break;
  625.                                 case 6:
  626.                                         hhh();//仿真运行
  627.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  628.                                         break;
  629.                                 case 7:
  630.                                         closegraph();//关闭绘图环境
  631.                                         exit(0);//正常退出
  632.                                 default:
  633.                                         FlushMouseMsgBuffer();//单击事件后清空鼠标消息
  634.                                         //printf("\r\n(%d,%d)",m.x,m.y);//打印鼠标坐标,方便调试时确定区域
  635.                                         break;
  636.                                 }
  637.                                 break;
  638.                 }
  639.         }
  640.         return 0;
  641. }

复制代码

这是完整的代码 问题主要在float simulation()这组函数中,希望有大佬帮忙解答
最佳答案
2023-4-4 15:57:11
if(Bd>350 && Bd<450 && H>350 && H<450)  这个应该没啥问题啊   不都是并行的关系吗
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2023-4-4 15:57:11 | 显示全部楼层    本楼为最佳答案   
if(Bd>350 && Bd<450 && H>350 && H<450)  这个应该没啥问题啊   不都是并行的关系吗
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-4-4 16:03:58 | 显示全部楼层
wp231957 发表于 2023-4-4 15:57
if(Bd>350 && Bd350 && H

但是我输入Bd=400,H=400这种明明在范围内的数,却不会出现图形,如果我把if语句删掉,单纯赋值又能出现 图形,我觉得应该是if语句没用对
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-10 15:06

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表